CentOS7编译安装MySQL5.7.24的教程详解
程序员文章站
2022-12-06 23:43:08
安装依赖
(1)cmake是新版mysql的编译工具
sudo yum install gcc gcc-c++ pcre pcre-devel openssl...
安装依赖
(1)cmake是新版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
2.解压并改名
tar zxvf boost_1_59_0.tar.gz mv boost_1_59_0 boost
3.在预编译安装mysql时要加上-dwith_boost=/usr/local/boost
编译安装mysql
# 添加mysql用户 useradd -s /sbin/nologin -m mysql # 下载mysql wget https://dev.mysql.com/get/downloads/mysql-5.7/mysql-5.7.24.tar.gz # 解压mysql tar 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/local ln -s mysql-5.7.24 mysql # 添加到环境变量 vim /etc/profile export path=/usr/local/mysql/bin:$path export path=/usr/local/mysql/bin:/usr/local/mysql/lib:$path source /etc/profile cd /usr/local/mysql-5.7.24 mkdir -p /usr/local/mysql-5.7.24/{data,tmp,logs,pids} chown mysql.mysql /usr/local/mysql-5.7.24/data chown mysql.mysql /usr/local/mysql-5.7.24/tmp chown mysql.mysql /usr/local/mysql-5.7.24/logs chown mysql.mysql /usr/local/mysql-5.7.24/pids # 修改/etc/my.cnf文件,编辑配置文件如下 [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_general_ci datadir=/usr/local/mysql/data socket=/usr/local/mysql/tmp/mysql.sock [mysqld_safe] log-error=/usr/local/mysql/logs/mysqld.log pid-file=/usr/local/mysql/pids/mysqld.pid [client] default-character-set=utf8mb4 # 创建mysqld.log 和 mysqld.pid文件 touch /usr/local/mysql/logs/mysqld.log touch /usr/local/mysql/pids/mysqld.pid chown mysql.mysql -r /usr/local/mysql/logs/ chown mysql.mysql -r /usr/local/mysql/pids/ # 加入守护进程 cd /usr/local/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod a+x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on # 初始化数据库, –initialize 表示默认生成一个安全的密码,–initialize-insecure 表示不生成密码 mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data # 启动mysql service mysqld start
这里给一张/etc/my.cnf的配置图示
登录mysql,修改密码
mysql -u root -p #第一次登陆不需要密码,回车即可 set password for root@localhost = password('root'); #修改密码
总结
以上所述是小编给大家介绍的centos7编译安装mysql5.7.24的教程详解,希望对大家有所帮助
上一篇: 用php解析html的实现代码
下一篇: Docker默认网段的正确修改步骤