源码编译安装MySQL-5.5
一、安装cmake
[root@localhost src]# tar xf cmake-2.8.8.tar.gz
[root@localhost src]# cd cmake-2.8.8
[root@localhost cmake-2.8.8]# ./bootstrap
[root@localhost cmake-2.8.8]# make && make install
二、编译安装mysql-5.5.25a
1、使用cmake编译mysql-5.5
2、编译安装
①准备数据存放的文件系统
[root@localhost init.d]# fdisk /dev/sda
//其中过程省略。。
[root@localhost init.d]# partprobe /dev/sda
//创建逻辑卷
[root@localhost init.d]# pvcreate /dev/sda5
Writing physical volume data to disk "/dev/sda5"
Physical volume "/dev/sda5" successfully created
[root@localhost init.d]# vgcreate myvg /dev/sda5
Volume group "myvg" successfully created
[root@localhost init.d]# lvcreate -n mydata -L 5G myvg
Logical volume "mydata" created
[root@localhost init.d]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mydata myvg -wi-a- 5.00G
lvtext vgtext -wi-a- 1.00G
home vol0 -wi-ao 4.88G
root vol0 -wi-ao 29.28G
[root@localhost init.d]# mke2fs -j /dev/myvg/mydata
//设置开机挂载
[root@localhost ~]# mkdir /mydata
[root@localhost ~]# vim /etc/fstab
//添加如下内容
/dev/myvg/mydata /mydata ext3 defaults 0 0
[root@localhost ~]# mount –a //重新挂载
[root@localhost ~]# mkdir /mydata/data //作为数据的挂载目录
②新建用户以安全方式运行进程:
//创建用户
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
[root@localhost ~]# chown -R mysql:mysql /mydata/data
③安装并初始化mysql
//开始进行编译
[root@localhost src]# tar xf mysql-5.5.25a.tar.gz
[root@localhost src]# cd mysql-5.5.25a
[root@localhost src]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWITH_READLINE=1-DWITH_SSL=system-DWITH_ZLIB=system-DWITH_LIBWRAP=0-DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci
[root@localhost src]# make && make install
[root@localhost mysql-5.5.25a]# cd ..
[root@localhost src]# cd ..
[root@localhost local]# pwd
/usr/local
[root@localhost local]# ln -sv /usr/local/src/mysql-5.5.25a mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]#scripts/mysql_install_db --user=mysql--datadir=/mydata/data
Installing MySQL system tables...
④为mysql提供主配置文件:
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf
//并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
//另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data //添加此行指定mysql数据文件的存放位置
⑤为mysql提供sysv服务脚本:
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
//添加至服务列表:
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
⑥输出mysql的man手册至man命令的查找路径:
[root@localhost mysql]# vim /etc/man.config
#####################mysql#############
MANPATH /usr/local/mysql/man
⑦输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
[root@localhost mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
create symbolic link `/usr/include/mysql' to `/usr/local/mysql/include'
⑧输出mysql的库文件给系统库查找路径:
[root@localhost ld.so.conf.d]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
⑨修改PATH环境变量,让系统可以直接使用mysql的相关命令。
export PATH=$PATH:/usr/local/mysql/bin