目录规划
/mysql 软件目录
/data 数据目录
/logs 日志目录

1.解压安装包

tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /
mv /mysql-8.0.20-linux-glibc2.12-x86_64 /mysql

2.创建Mysql组和mysql用户

groupadd mysql;useradd -g mysql mysql

3.创建数据目录和日志目录

mkdir /data
mkdir /logs
chown mysql.mysql /data
chown mysql.mysql /logs

4.编辑/etc/my.cnf文件

[client]
port=3306
socket=/tmp/mysql.sock

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

5.初始化Mysql

[root@mysql80020 tmp]# /mysql/bin/mysqld --initialize  --user=mysql --basedir=/mysql --datadir=/data
2020-06-26T09:24:51.693846Z 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-06-26T09:24:51.693971Z 0 [System] [MY-013169] [Server] /mysql/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 2487
2020-06-26T09:24:51.703239Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-26T09:24:54.070497Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-06-26T09:24:56.662081Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ylGI0gf_1Hb-

6.拷贝mysql启动文件到系统初始化目录

cp /mysql/support-files/mysql.server /etc/init.d/mysqld

7.启动mysql

service mysqld start

8.添加mysql环境变量

PATH=$PATH:$HOME/bin:/mysql/bin
export PATH

9.修改密码

[root@mysql80020 logs]# mysql -uroot -p
mysql> alter user 'root'@'localhost' identified by 'wwwwww';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

退出后再次登录

[root@mysql80020 logs]# mysql -uroot -pwwwwww
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 9
Server version: 8.0.20 MySQL Community Server - GPL

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>