1. 检测安装环境
[root@mapple:/root]# cat /etc/redhat-release
[root@mapple:/root]# uname -r
[root@mapple:/root]# rpm -qa | grep mysql
2. 下载Cmake安装包编译安装cmake
1)下载解压cmake
[root@mapple:/root]# wget https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3.tar.gz
[root@mapple:/root]# tar -xzf cmake-3.15.3.tar.gz
2)编译安装cmake
[root@mapple:/root]# yum install gcc-c++ gcc
[root@mapple:/root]# yum groupinstall "Compatibility" "Libraries Base" "Development tools" -y
[root@mapple:/root]# yum groupinstall "debugging Tools" "Dial-up Networking Support" -y
[root@mapple:/root]#yum -y install libaio-devel openssl openssl-devel
[root@mapple:/root]# cd cmake-3.15.3/
[root@mapple:/root/cmake-3.15.3]# ./configure
[root@mapple:/root/cmake-3.15.3]# gmake
[root@mapple:/root/cmake-3.15.3]# echo $? (此步骤可省略)
[root@mapple:/root/cmake-3.15.3]# gmake install
[root@mapple:/root/cmake-3.15.3]# yum install ncurses-devel ncurses -y
2)创建mysql用户组和创建mysql用户
[root@mapple:/root]# groupadd mysql
[root@mapple:/root]# useradd -g mysql -M -s /sbin/nologin mysql
[root@mapple:/root]# id mysql
[root@mapple:/root]# mkdir -p /usr/local/mysql/data
[root@mapple:/root]# chown -R mysql:mysql /usr/local/mysql
[root@mapple:/root]# chmod -R 755 /usr/local/mysql
4)下载MySQL安装包并解压
[root@mapple:/root]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz
[root@mapple:/root]# tar -xzf mysql-boost-8.0.11.tar.gz -C /usr/local
5)Cmake编译安装mysql
[root@mapple:/root]# cd /usr/local/mysql-8.0.11
[root@mapple:/usr/local/mysql-8.0.11]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/mysql-8.0.11/boost
[root@mapple:/usr/local/mysql-8.0.11]# make && make install
[root@mapple:/usr/local/mysql-8.0.11]# vim /etc/my.cnf
#添加:
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[client]
socket=/var/lib/mysql/mysql.sock
[root@mapple:/usr/local/mysql-8.0.11]# bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
[root@mapple:/usr/local/mysql-8.0.11]# bin/mysql_ssl_rsa_setup
注:如果出现[ERROR] [MY-010457] [Server] --initialize specified but the data
directory has files in it. Aborting.
则需要删除/usr/local/mysql/data下的数据后重新初始化即可[root@mysql:/usr/local/mysql/data]#
rm -rf *
7)将mysql的启动服务添加到系统服务中
[root@mapple:/usr/local/mysql-8.0.11]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mapple:/usr/local/mysql-8.0.11]# chmod +x /etc/init.d/mysqld
8)创建软链接
[root@mysql:/usr/local/mysql-8.0.11]# ln -s /usr/local/mysql-8.0.11 /usr/local/mysql
9) 配置环境变量
[root@mapple:/usr/local/mysql/bin]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[root@mapple:/usr/local/mysql/bin]# tail -1 /.etc/profile
[root@mapple:/usr/local/mysql/bin]# source /etc/profile
[root@mapple:/usr/local/mysql/bin]# echo $PATH
[root@mapple:/]# chmod -R 1777 /tmp/
[root@mysql:/usr/local/mysql-8.0.11]# /etc/init.d/mysqld start
注:如果出现“mysqld_safe error: log-error set to
‘/var/log/mariadb/mariadb.log’, however file don’t exists. Create
writable for user ‘mysql’”
如果出现 “Starting MySQL.2019-09-30T13:28:41.680478Z mysqld_safe Directory ‘/var/lib/mysql’ for UNIX socket file don’t exists. ERROR!
The server quit without updating PID file
(/usr/local/mysql/data/mysql.pid).”
[root@mapple:/usr/local/mysql-8.0.11]# mkdir -p /var/log/mariadb
[root@mapple:/usr/local/mysql-8.0.11]# touch /var/log/mariadb/mariadb.log
[root@mapple:/usr/local/mysql-8.0.11]# chown -R mysql:mysql /var/log/mariadb/
[root@mapple:/usr/local/mysql-8.0.11]# mkdir /var/run/mariadb/
[root@mapple:/usr/local/mysql-8.0.11]# chown -R mysql:mysql /var/run/mariadb/
[root@mapple:/usr/local/mysql-8.0.11]# mkdir /var/lib/mysql
[root@mapple:/usr/local/mysql-8.0.11]# chmod 777 /var/lib/mysql
11)启动MySQL程序
[root@mapple:/usr/local/mysql-8.0.11]# /etc/init.d/mysqld start
[root@mapple:/usr/local/mysql-8.0.11]# ps -ef | grep mysql
[root@mapple:/usr/local/mysql-8.0.11]# netstat -lntup | grep 3306
[root@mapple:/usr/local/mysql-8.0.11]# mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by "oracle2019";
mysql> show databases;
[root@node03:/usr/local/mysql-8.0.11]# firewall-cmd --permanent --add-service=mysql
[root@node03:/usr/local/mysql-8.0.11]# firewall-cmd --permanent --add-port=3306/tcp
[root@node03:/usr/local/mysql-8.0.11]# firewall-cmd --reload