CentOS 7源码安装MySQL 5.7.17
1. 安装环境:CentOS 7 64位 MySQL 5.7
2. 去MySQL官方网站下载MySQL源码安装包,注意,一定要选择下图的源代码版,否则cmake时会报错:
3. 预先安装依赖软件:
yum install -y gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl perl-Data-Dumper
4. 创建MySQL用户和用户组
先查看是否已经创建:
cat /etc/passwd | grep mysql
cat /etc/group | grep mysql
没有创建则新建mysql用户以及用户组:
1 groupadd mysql
2 useradd -r -g mysql mysql
5. 我把源码包放在了/tmp目录下,解压缩MySQL
tar -zxv -f mysql-5.7.17.tar.gz
6. 创建MySQL安装目录和数据目录
1 mkdir /usr/local/mysql
2 mkdir /usr/local/mysql/data
7. 创建boost文件夹并复制boost文件到这个目录中,否则cmake会报错,本示例中使用的是boost_1_59_0.tar.gz
mkdir /usr/local/boost
cp /tmp/boost_1_59_0.tar.gz /usr/local/boost/
8. cmake安装MySQL
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/usr/local/mysql/data
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
-DWITH_BOOST=/usr/local/boost/boost_1_59_0.tar.gz
9. 安装过程会持续一段时间,耐心等待。
make && make install
10. 安装完成之后修改/etc/my.cnf
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
symbolic-links=0
skip-grant-tables
[mysqld_safe]
log-error=/usr/local/mysql/logs/mysql.log
pid-file=/usr/local/mysql/localhost.localdomain.pid
!includedir /etc/my.cnf.d
mkdir /usr/local/mysql/logs
11. 修改MySQL目录所有者
chown -R mysql:mysql /usr/local/mysql
12. 添加MySQL服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
13. 启动MySQL
service mysql start
显示启动成功:Starting MySQL....... SUCCESS!
14. 开启MySQL
/usr/local/mysql/bin/mysql -uroot -p
15. 完成!