所需文件:mysql-xx.tar.gz ,此处我使用官网下载的最新版mysql-5.6.35.tar.gz
1. 安装依赖:# yum install -y cmake ncurses-devel bison
2. 针对Centos6.4版本以上用户,修改/etc目录下的my.cnf文件,更名为my.cnf.bak,否则会影响Mysql正常启动
3.解压源码包:# tar -zxvf mysql-5.6.35.tar.gz
4. 进入Mysql源码包目录:# cd mysql-5.6.35
5. 配置,设置相关选项:# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1
6. # make && make install
7. 添加Mysql组及Mysql用户:# groupadd mysql
# useradd -r -g mysql mysql
8. 修改/usr/local/mysql权限:# chown R mysql:mysql /usr/local/mysql
9. 进入Mysql安装路径:# cd /usr/local/mysql
10. 初始化配置脚本,创建系统自带数据库及数据表:# scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql
11. 配置文件复制:# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
12. 修改配置文件:# vim /etc/my.cnf
13. [client]
port = 3306
socket = /usr/local/mysql/mysql.sock(和cmake中关于socket文件路径一致)
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /usr/local/mysql/mysql.sock
14. 将Mysql启动命令加入PATH环境变量:# vim /etc/profile
加入以下内容: PATH=$PATH:/usr/local/mysql/bin
export PATH
保存退出,执行:# source /etc/profile