官方参考手册:https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
参考:https://www.cnblogs.com/chenqs/p/8911670.html
1.下载mysql8.0源码包
mysql-boost-8.0.20.tar.gz:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.20.tar.gz
2.安装依赖
此处需要cmake3版本
yum install -y cmake3 ncurses ncurses-devel libaio-devel openssl openssl-devel
GCC要求5.3以上版本
参考:https://blog.csdn.net/jiantong0737/article/details/102470950
yum install -y centos-release-scl scl-utils-build
yum install -y devtoolset-7-gcc.x86_64 devtoolset-7-gcc-c++.x86_64 devtoolset-7-gcc-gdb-plugin.x86_64
export PATH=$PATH:/opt/rh/devtoolset-7/root/usr/bin/
3.添加用户,并创建安装目录、数据目录
useradd -r -s /bin/false mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod 755 /usr/local/mysql -R
chmod 755 /data/mysql -R
4.解压源码包
cd /usr/local
tar zxvf mysql-boost-8.0.20.tar.gz
5.配置、编译、安装
若编译失败,清理后重新编译
make clean
rm CMakeCache.txt
cd mysql-8.0.20
mkdir bld
cd bld
cmake3 .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.20/boost/
make && make install
6.???
cd /usr/local/mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
7.配置/etc/my.cnf
自定义配置
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/data/mysql
8.初始化并启动mysql
export PATH=$PATH:/usr/local/mysql/bin (vi /etc/profile)
mysqld --initialize --user=mysql --datadir=/data/mysql/
mysql_ssl_rsa_setup
mysqld_safe --user=mysql &
9.注册服务并设置开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql.server
service mysql.server restart 或 systemctl restart mysql.server
systemctl enable mysql.server 或 /sbin/chkconfig mysql.server on
10.修改密码并设置外网访问
alter user 'root'@'localhost' identified by '123456';
create user 'root'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;