1. 卸载其他版本的MySQL
[root@db01 tools]# for i in $(rpm -qa |grep -E "^mysql-");do rpm -e $i --nodeps;done
2. 安装编译代码需要的包
[root@db01 tools]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel openssl-devel
3. 编译安装mysql-5.7.30
# 创建mysql虚拟用户,并加入到mysql组
[root@db01 tools]# groupadd mysql
[root@db01 tools]# useradd -g mysql mysql -M -s /sbin/nologin
[root@db01 tools]# cd /data/tools
# 下载mysql,解压
[root@db01 tools]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.30.tar.gz
[root@db01 tools]# tar -zxvf mysql-5.7/mysql-boost-5.7.30.tar.gz
[root@db01 tools]# cd mysql-5.7.30
# 编译安装
[root@db01 mysql-5.7.30]# /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=/data/tools/mysql-5.7.30/boost
[root@db01 src]# make && make install
# 创建数据存储目录,并赋予权限
[root@db01 mysql-5.7.30]# mkdir /data/mysql/data -p
[root@db01 mysql-5.7.30]# chown -R mysql.mysql /data/mysql
# 初始化数据库
[root@db01 mysql-5.7.30]# /data/mysql/bin/mysqld --basedir=/data/mysql --datadir=/data/mysql/data --user=mysql --initialize
# 配置my.cnf
root@db01 mysql-5.7.30]# cat /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/var/mysql.sock
[mysqld]
port = 3306
socket = /data/mysql/var/mysql.sock
basedir = /data/mysql/
datadir = /data/mysql/data
pid-file = /data/mysql/data/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
sync_binlog=1
log_bin = mysql-bin
# 启动mysql服务
root@db01 mysql-5.7.30]# cd /data/mysql
[root@db01 mysql]# mkdir var
[root@db01 mysql]# chown -R mysql.mysql var
[root@db01 mysql]# cp -rp support-files/mysql.server /etc/init.d/mysql
[root@db01 mysql]# cd /etc/init.d
[root@db01 init.d]# chkconfig mysql on
[root@db01 init.d]# service mysql start
# 设置环境变量
[root@db01 mysql]# echo "export PATH=$PATH:/data/mysql/bin" >> /etc/profile
[root@db01 mysql]# source /etc/profile
[root@db01 mysql]# /bin/mkdir -p /var/lib/mysql
[root@db01 mysql]# ln -s /data/mysql/var/mysql.sock /var/lib/mysql/mysql.sock
# 修改密码
[root@db01 mysql]# vim /etc/my.cnf
......
[mysqld]
......
skip-grant-tables //先设置无密码登陆
[root@db01 mysql]# service mysql.service restart
[root@db01 mysql]# mysql
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password for root@localhost = password('123456');
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 删除配置文件的skip-grant-tables
# 到此,使用mysql -uroot -p123456登录mysql
4. 配置systemd管理mysql
- 先停止数据库service mysql.service stop
[root@lb01 system]$ cat /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@lb01 system]$ systemctl start mysqld.service
[root@lb01 system]$ systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2020-07-19 15:36:00 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 31801 (mysqld)
CGroup: /system.slice/mysqld.service
└─31801 /data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.162630Z 0 [Note] Foun...m.
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.162667Z 0 [Note] Skip...y.
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.163506Z 0 [Warning] C...d.
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.163594Z 0 [Note] Skip...y.
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.163714Z 0 [Note] Serv...06
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.163744Z 0 [Note] - ...';
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.163769Z 0 [Note] Serv...'.
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.168871Z 0 [Note] Fail...''
7月 19 15:36:01 lb01 mysqld[31801]: 2020-07-19T07:36:01.174950Z 0 [Note] /dat...s.
7月 19 15:36:01 lb01 mysqld[31801]: Version: '5.7.30-log' socket: '/data/mys...on
Hint: Some lines were ellipsized, use -l to show in full.