1. 下载

# 下载 mysql
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.20-el7-x86_64.tar.gz
# 解压缩
tar -zxvf mysql-8.0.20-el7-x86_64.tar.gz
# 重命名
mv mysql-8.0.20-el7-x86_64 /data/software/mysql
# 进入目录
cd /data/software/mysql

2. 创建用户及用户组

groupadd mysql
useradd -g mysql mysql

3. 创建日志及进程文件,并赋予权限

mkdir /var/log/mariadb /var/run/mariadb
touch /var/log/mariadb/mariadb.log /var/run/mariadb/mariadb.pid
chown -R mysql:mysql /var/log/mariadb /var/run/mariadb

4. 修改配置

vim /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/data/software/mysql
datadir=/data/software/mysql/data

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

5. 初始化

[root@localhost mysql]# /data/software/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/software/mysql/ --datadir=/data/software/mysql/data/
2020-05-07T15:40:08.278047Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-05-07T15:40:08.278154Z 0 [System] [MY-013169] [Server] /data/software/mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 2524
2020-05-07T15:40:08.291519Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-07T15:40:08.558052Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-05-0715:40:09.093362Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ToX3>VJQuFrt

6. 启动

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# service mysqld start
Starting MySQL                                             [  OK  ]
[root@localhost mysql]# bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# 修改密码
mysql> alter user 'root'@'localhost' identified by 'root'; 
Query OK, 0 rows affected (0.01 sec)

# 修改 root 用户可以远程连接
mysql> update mysql.user set host = '%' where user = 'root'; 
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

# 刷新
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)

7. 开放端口

# 开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重载入
firewall-cmd --reload

Q.E.D.


盛年不重来,一日难再晨。