CentOS7编译安装MySQL5.7.24的教程详解

目录

安装依赖

(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 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.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的配置图示

CentOS7编译安装MySQL5.7.24的教程详解

登录MySQL,修改密码

mysql -u root -p #第一次登陆不需要密码,回车即可
set password for root@localhost = password('root'); #修改密码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论