1.进入MySQL官网下载MySQL源代码
依次点击Downloads -> Community -> MySQL Community Server
源代码
1.Select Operating System: Source Code
2.Select OS Version: Generic Linux (Architecture Independent)
再下载列表中选择 1.Compressed TAR Archive、2.Compressed TAR Archive, Includes Boost Headers 下载
将上述两个源代码包在同一目录下将解压
1.安装编译环境及目录的设置
yum install -y cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
tar -zxvf mysql-5.7.17.tar.gz
rm -rf mysql-5.7.17.tar.gz
tar -zxvf mysql-boost-5.7.18.tar.gz
rm -rf mysql-boost-5.7.18.tar.gz
useradd -M -s /sbin/nologin mysql
mkdir -pv /usr/local/mysql/mydata
mkdir -pv /usr/local/mysql/conf
chown -R mysql /usr/local/mysql
rm -rf /etc/my.cnf
必须删除my.cnf,其为mariadb配置文件,于mysql有冲突
如果linux运行内存小于2G,建议设置虚拟内存
dd if=/dev/zero of=/swapfile bs=64M count=32
mkswap /swapfile
swapon /swapfile
在软件编译完成之后,删除交换分区
rm /swapfile
2.配置cmake,编译安装
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/mydata
-DSYSCONFDIR=/usr/local/mysql/conf
-DMYSQL_USER=mysql
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DENABLE_DOWNLOADS=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_DEBUG=0
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled
-DWITH_ZLIB:STRING=bundled
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=./boost
make
make install
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql [MySQL安装的根目录]
-DMYSQL_DATADIR=/mydata/mysql/data [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc [MySQL配置文件所在目录]
-DMYSQL_USER=mysql [MySQL用户名]
-DWITH_MYISAM_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 [MySQL的数据库引擎]
-DWITH_READLINE=1 [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock [MySQL的通讯目录]
-DMYSQL_TCP_PORT=3306 [MySQL的监听端口]
-DENABLED_LOCAL_INFILE=1 [启用加载本地数据]
-DENABLE_DOWNLOADS=1 [编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=utf8 [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci [设置默认字符校对]
-DWITH_DEBUG=0 [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=0
-DWITH_SSL:STRING=bundled [通讯时支持ssl协议]
-DWITH_ZLIB:STRING=bundled [允许使用zlib library]
-DDOWNLOAD_BOOST=1 [允许在线更新boost库]
-DWITH_BOOST=/boost [指定boost安装路径]
boost安装路径即为2.Compressed TAR Archive, Includes Boost Headers的解压目录
3.设置添加到系统服务并设置开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
4.将mysql添加到bash
cp /usr/local/mysql/bin/mysql /usr/bin/mysql
5.初始化mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/mydata
6.重新设置mysql密码
set password =password('123456');