centos 7 源码安装mysql
下载mysql5.7
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14.tar.gz
下载boost_1_59_0:
http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
下载支持包
yum -y install cmake ncurses ncurses-devel bison bison-devel boost boost-devel
新建用户
useradd -s /bin/nologin mysql
创建数据库目录
mkdir /mydata/data
修改权限
chown -R mysql.mysql /mydata/data
安装准备:
tar xf mysql-5.7.14.tar.gz
tar xf boost_1_59_0.tar.gz
cd mysql-5.7.14.tar.gz
编译:cmake -DCMAKE_INSTALL_PREFIX="/usr/local/mysql" -DDEFAULT_CHARSET=utf8 -DMYSQL_DATADIR="/mydata/data/" -DINSTALL_PLUGINDIR=plugin -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_COLLATION=utf8_general_ci -DENABLE_DEBUG_SYNC=0 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=1 -DWITH_ZLIB=system -DWITH_EXTRA_CHARSETS=none -DMYSQL_MAINTAINER_MODE=OFF -DEXTRA_CHARSETS=all -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/boost_1_59_0
make && make install
chgrp -R mysql /usr/local/mysql
初始化:
cd /usr/local/mysql/bin/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data
控制mysql启动脚本:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
chkconfig --add mysqld
优化MySQL命令的执行路径
[root@mysql ~]# cat /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@mysql ~]# source /etc/profile.d/mysql.sh
导出MySQL的库文件
[root@mysql ld.so.conf.d]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@mysql ld.so.conf.d]# ldconfig
[root@mysql ld.so.conf.d]# ldconfig -v | grep mysql
/usr/local/mysql/lib:
libmysqlclient.so.18 -> libmysqlclient_r.so.18.1.0
[root@mysql ld.so.conf.d]#
导出MySQL的头文件
[root@mysql ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
复制MySQL的配置文件
[root@mysql mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@mysql mysql]# vim /etc/my.cnf
innodb_file_per_table = 1
datadir = /mydata/data
port = 3306
user = mysql
server_id = 1
socket = /tmp/mysql.sock
[root@mysql mysql]# service mysqld start
[root@mysql ~]# netstat -antp | grep :3306
tcp 0 0 :::3306 :::* LISTEN 19767/mysqld
[root@mysql ~]#