1、下载mysql源码压缩包,以及cmake的rpm包: boost_1_59_0.tar.gz mysql-5.7.19.tar.gz cmake-2.8.12.2-4.el6.x86_64.rpm 2、解压压缩包,并移动到相应的位置(不固定): cp -rf boost_1_59_0 /usr/local/boost cp -rf mysql-5.7.19 /usr/local/mysql 3、创建用户和组: groupadd mysql useradd -g mysql mysql 4、安装编译环境依赖包(配置好yum,并挂载): yum install gcc gcc-c++ -y yum install -y ncurses-devel.x86_64 yum install -y cmake.x86_64 yum install -y libaio.x86_64 yum install -y bison.x86_64 yum install -y gcc-c++.x86_64 5、安装cmake: yum -y localinstall cmake-2.8.12.2-4.el6.x86_64.rpm 6、创建目录: mkdir -p /home/mysql3306/mysql3306 mkdir -p /home/mysql3306/logs 给目录赋权限: chown -R mysql:mysql /usr/local/mysql chown -R mysql:mysql /home/mysql3306 7、在MySQL安装目录进行编译安装: cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql3306/mysql3306 -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_BOOST=/usr/local/boost 8、完成之后执行:make && make install 9、将mysql.server加入到服务 (因人而异,不是必须的): cd /usr/local/mysql/support-files cp mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld 10、配置MySQL的配置文件my.cnf(此处配置文件过于简单,可以根据 需要进行增加): #vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /home/mysql3306/mysql3306 port = 3306 #character utf8 character_set_server=utf8 init_connect='SET NAMES utf8' [client] default-character-set=utf8 socket=/tmp/mysql.sock 11、对MySQL进行初始化(5.7版本 注意初始化的命令): /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --basedir=/usr/local/mysql --datadir=/home/mysql3306/mysql3306/ --user=mysql 12、启动MySQL服务:service mysqld start 13、进入MySQL初始化权限,给root修改密码。因为初始化时加入了--initialize-insecure参数可以免密登陆,不加的话会在error log中生成默认密码。