1.确定系统版本
[root@station253 ~]# head -n1 /etc/issue
CentOS release 6.4 (Final)
[root@station253 ~]# uname -r
2.6.32-358.el6.x86_64
[root@station253 ~]# cat /proc/version
Linux version 2.6.32-358.el6.x86_64
[root@station253 ~]# ls /mnt/hgfs/Share64/mysql
mysql-5.5.33-linux2.6-x86_64.tar.gz
此版本是绿色解压缩直接执行版本
2.确定事先没有rpm包安装过mysql
[root@station253 ~]# rpm -qa | grep mysql
3.安装所需要的库文件
[root@station253 ~]# yum -y install gcc gcc-c++ cmake bison
4.创建用户和组
[root@station253 ~]# groupadd -r mysql
## -r此参数是用来建立系统帐号。它会自动帮你选定一个小于499的gid
[root@station253 ~]# useradd -g mysql -r -M -s /bin/nologin mysql
## -g 所属组 –r 建立系统账号 –M 不建立用户家目录 –s 用户默认shell是禁止用户登陆系统
[root@station253 ~]# id mysql
uid=498(mysql) gid=499(mysql) groups=499(mysql)
5.创建数据存放目录data
[root@station253 ~]# mkdir -pv /mydata/data
## -p 连同父目录 –v 详细情况
Mysql的数据文件应该独立存放。最起码是单独分区上,分区做成Raid5或Raid10,或者做成LVM逻辑卷。
因此,这里先做逻辑卷,再将数据库存放到那里。
[root@station253 ~]# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c6755
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
/dev/sda2 26 791 6144000 83 Linux
/dev/sda3 791 918 1024000 83 Linux
/dev/sda4 918 2611 13597696 5 Extended
/dev/sda5 919 1046 1024000 82 Linux swap / Solaris
Command (m for help): n
First cylinder (1046-2611, default 1046):
Using default value 1046
Last cylinder, +cylinders or +size{K,M,G} (1046-2611, default 2611): +5G
Command (m for help): n
First cylinder (1700-2611, default 1700):
Using default value 1700
Last cylinder, +cylinders or +size{K,M,G} (1700-2611, default 2611): +5G
Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): 8e #创建一个新分区类型为8e
Changed system type of partition 6 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
[root@station253 ~]# partprobe /dev/sda
#RHEL5.x上partprobe在RHEL6.x下已经不适用,新命令partx
-bash: partprobe: command not found
[root@station253 ~]# partx -a /dev/sda #让内核重新读取分区
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@station253 ~]# fdisk /dev/sda
Command (m for help): p
/dev/sda6 1046 1699 5247314 8e Linux LVM
/dev/sda7 1700 2353 5253223+ 8e Linux LVM
[root@station253 ~]# vgcreate myvg /dev/sda{6,7}
-bash: vgcreate: command not found
#老版本的vgcreate是在新lvm2包中,安装
[root@station253 ~]# yum -y install lvm2
[root@station253 ~]# pvcreate /dev/sda{6,7} #创建物理卷
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
[root@station253 ~]# vgcreate myvg /dev/sda{6,7} #创建卷组
Volume group "myvg" successfully created
[root@station253 ~]# vgs #查看卷组或命令lvdisplay
VG #PV #LV #SN Attr VSize VFree
myvg 2 0 0 wz--n- 10.01g 10.01g
[root@station253 ~]# lvcreate -L 5G -n mydata myvg #创建逻辑卷
Logical volume "mydata" created
[root@station253 ~]# lvs #查看逻辑卷
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a---- 5.00g
[root@station253 ~]# mkfs.ext4 /dev/myvg/mydata #格式化
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6. 挂载设置
[root@station253 ~]# vim /etc/fstab #修改挂载配置文件
#新增一行
/dev/myvg/mydata /mydata/data ext4 defaults 0 0
[root@station253 ~]# mount -a #挂载
[root@station253 ~]# reboot #虚拟机挂载不出时重启系统
[root@station253 ~]# mount|sort #查看所有挂载
/dev/mapper/myvg-mydata on /mydata/data type ext4 (rw)
[root@station253 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/myvg-mydata
ext4 5.0G 138M 4.6G 3% /mydata/data
7.数据目录配置
[root@station253 ~]# chown -R mysql.mysql /mydata
[root@station253 ~]# ll -d /mydata
drwxr-xr-x 3 mysql mysql 4096 Dec 14 17:11 /mydata
[root@station253 ~]# ll -d /mydata/data
drwxr-xr-x 3 mysql mysql 4096 Dec 14 17:39 /mydata/data
8.编译安装
[root@station253 ~]# cp /mnt/hgfs/Share64/mysql/mysql-5.5.33-linux2.6-x86_64.tar.gz /opt
[root@station253 ~]# cd /opt
[root@station253 opt]# tar zxvf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local
[root@station253 opt]# ls /usr/local/mysql-5.5.33-linux2.6-x86_64/
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
[root@station253 opt]# cd /usr/local/
[root@station253 local]# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql
`mysql' -> `mysql-5.5.33-linux2.6-x86_64'
生产环境下,做软连接是为写参数和升级方便
[root@station253 mysql]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #安装目录
-DMYSQL_DATADIR=/var/mysql/data \ #数据库存放目录
-DMYSQL_USER=mysql \ #默认用户
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ #Unix socket 文件路径
-DDEFAULT_CHARSET=utf8 \ #使用 utf8 字符集
-DDEFAULT_COLLATION=utf8_general_ci \ #校验字符集
-DWITH_EXTRA_CHARSETS=all \ #安装所有扩展字符集
-DWITH_MYISAM_STORAGE_ENGINE=1 \ #安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安装 innodb 存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \ #安装 memory 存储引擎
-DWITH_READLINE=1 \ #快捷键功能
-DENABLED_LOCAL_INFILE=1 \ #允许从本地导入数据
-DMYSQL_TCP_PORT=3306 #MySQL 监听端口
-DWITH_SSL=yes \ #支持 SSL
CMake Error The source directory usr local does not appear to contain CMakeLists.txt
因此版本为绿色版,没有CMakeLists.txt
如果之前因为库文件安装不全,编译失败,安装完全的库文件之后,再次编译失败,则需要删除编译文件。# rm -rf CMakeCache.txt
9.配置mysql环境
#为Mysql提供Sysv服务脚本
[root@station253 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#添加执行权限并加入到系统服务
[root@station253 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@station253 mysql]# chmod 755 /etc/init.d/mysqld
[root@station253 mysql]# chkconfig --add mysqld
#提供Mysql主配置文件,大于512MB内存使用该配置文件
[root@station253 mysql]# cp support-files/my-large.cnf /etc/my.cnf
#修改主配置文件数据存放目录位置
[root@station253 mysql]# vim /etc/my.cnf
在[mysqld]中最后添加
38 datadir = /mydata/data
40 thread_concurrency = 2 //8改成2,并发进程数是CPU颗数2倍
#添加Mysql的PATH环境变量
[root@station253 mysql]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@station253 mysql]# . /etc/profile
#添加Mysql的库文件
[root@station253 mysql]# echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
[root@station253 mysql]# ldconfig
#添加Mysql头文件信息
[root@station253 mysql]# ln -s /usr/local/mysql/include /usr/include/mysql
#启动进程
[root@station253 mysql]# service mysqld start
Starting MySQL. ERROR! The server quit without updating PID file (/mydata/data/station253.example.com.pid).
10.排错
#查询错误日志
[root@station253 mysql]# cat /mydata/data/station253.example.com.err
131214 19:03:22 mysqld_safe Starting mysqld daemon with databases from /mydata/data
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
131214 19:03:22 mysqld_safe mysqld from pid file /mydata/data/station253.example.com.pid ended
#报错显示缺少共享库
[root@station253 mysql]# rpm -qa | grep libaio
#果然没有安装,安装它
[root@station253 mysql]# yum -y install libaio
libaio-0.3.107-10.el6.x86_64.rpm
#启动进程
[root@station253 mysql]# service mysqld start
Starting MySQL. ERROR! The server quit without updating PID file (/mydata/data/station253.example.com.pid).
#查询错误日志
[root@station253 mysql]# cat /mydata/data/station253.example.com.err | egrep 'Note|ERROR'
131214 19:15:26 [Note] Plugin 'FEDERATED' is disabled.
131214 19:15:26 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
131214 19:15:28 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
131214 19:15:28 [Note] - '0.0.0.0' resolves to '0.0.0.0';
131214 19:15:28 [Note] Server socket created on IP: '0.0.0.0'.
131214 19:15:28 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
#出错原因是没有初始化
[root@station253 mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
Installing MySQL system tables...
OK
Filling help tables...
OK
#安装成功
[root@station253 mysql]# service mysqld start
Starting MySQL... SUCCESS!