CentOS7编译安装MySQL5.7.24的教程详解
时间:2020-11-03 13:38 作者:admin610456
安装依赖
(1)cmake是新版mysql/' target='_blank'>mysql的编译工具
sudo yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel sudo yum install zlib zlib-devel cmake ncurses ncurses-devel bison bison-devel如下的几个依赖在CentOS7中需要安装,CentOS6不需要sudo yum install perl perl-devel autoconf
安装boost
如果安装的MySQL5.7及以上的版本,在编译安装之前需要安装boost,因为高版本mysql需要boots库的安装才可以正常运行。否则会报CMake Error at cmake/boost.cmake:81错误
1.切换到/usr/local目录,然后在这个目录下下载boost
MySQL5.7.24要求boost的版本是1.59,更高版本的不适用MySQL5.7.24
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
2.解压并改名
tar zxvf boost_1_59_0.tar.gzmv boost_1_59_0 boost
3.在预编译安装MySQL时要加上-DWITH_BOOST=/usr/local/boost
编译安装MySQL
# 添加MySQL用户useradd -s /sbin/nologin -M mysql# 下载MySQLwget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz# 解压MySQLtar zxvf mysql-5.7.24.tar.gz# 进到MySQL目录cd mysql-5.7.24# 预编译cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.7.24 \-DWITH_BOOST=/usr/local/boost \-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.7.24/tmp/mysql.sock \-DMYSQL_DATADIR=/usr/local/mysql-5.7.24/data \-DDEFAULT_CHARSET=utf8mb4 \-DDEFAULT_COLLATION=utf8mb4_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_MYISAM_STORAGE_ENGINE=1 \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_MEMORY_STORAGE_ENGINE=1 \-DWITH_READLINE=1 \-DWITH_INNODB_MEMCACHED=1 \-DWITH_DEBUG=OFF \-DWITH_ZLIB=bundled \-DENABLED_LOCAL_INFILE=1 \-DENABLED_PROFILING=ON \-DMYSQL_MAINTAINER_MODE=OFF \-DMYSQL_TCP_PORT=3306# 编译&安装make && make install
配置
# 创建软连接cd /usr/localln -s mysql-5.7.24 mysql# 添加到环境变量vim /etc/profileexport PATH=/usr/local/mysql/bin:$PATHexport PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATHsource /etc/profilecd /usr/local/mysql-5.7.24mkdir -p /usr/local/mysql-5.7.24/{data,tmp,logs,pids}chown mysql.mysql /usr/local/mysql-5.7.24/datachown mysql.mysql /usr/local/mysql-5.7.24/tmpchown mysql.mysql /usr/local/mysql-5.7.24/logschown mysql.mysql /usr/local/mysql-5.7.24/pids# 修改/etc/my.cnf文件,编辑配置文件如下[mysqld]character-set-server=utf8mb4collation-server=utf8mb4_general_cidatadir=/usr/local/mysql/datasocket=/usr/local/mysql/tmp/mysql.sock[mysqld_safe]log-error=/usr/local/mysql/logs/mysqld.logpid-file=/usr/local/mysql/pids/mysqld.pid[client]default-character-set=utf8mb4# 创建mysqld.log 和 mysqld.pid文件touch /usr/local/mysql/logs/mysqld.logtouch /usr/local/mysql/pids/mysqld.pidchown mysql.mysql -R /usr/local/mysql/logs/chown mysql.mysql -R /usr/local/mysql/pids/# 加入守护进程cd /usr/local/mysqlcp support-files/mysql.server /etc/init.d/mysqldchmod a+x /etc/init.d/mysqldchkconfig --add mysqldchkconfig mysqld on# 初始化数据库, –initialize 表示默认生成一个安全的密码,–initialize-insecure 表示不生成密码mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data# 启动MySQLservice mysqld start
这里给一张/etc/my.cnf的配置图示
登录MySQL,修改密码
mysql -u root -p #第一次登陆不需要密码,回车即可set password for root@localhost = password('root'); #修改密码
总结
以上所述是小编给大家介绍的CentOS7编译安装MySQL5.7.24的教程详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
(责任编辑:admin)