[root@slave ~]# ls
anaconda-ks.cfg  mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
[root@slave ~]# tar -xf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
[root@slave ~]# ls
anaconda-ks.cfg  mysql-8.0.31-linux-glibc2.12-x86_64  mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
[root@slave ~]# mv mysql-8.0.31-linux-glibc2.12-x86_64 /usr/local/mysql
[root@slave ~]# groupadd mysql
[root@slave ~]# useradd -g mysql mysql
[root@slave ~]# chown -R mysql:mysql /usr/local/mysql/
[root@slave ~]# cd /usr/local/mysql/bin/
[root@slave bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize --lower-case-table-names=1
[root@slave bin]# cat > /etc/my.cnf<
[mysqld] 
basedir=/usr/local/mysql/ 
datadir=/usr/local/mysql/data/ 
socket=/tmp/mysql.sock 
character-set-server=UTF8MB4 
lower_case_table_names  = 1 
bind-address=0.0.0.0 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION EOF
[root@slave bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 
[root@slave bin]# service mysql start
[root@slave bin]# source /etc/profile
[root@slave bin]# mysql -u root -p
[root@slave bin]# cd
[root@slave ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit

Bye

[root@slave ~]# init 0

oot@slave bin]# mysql -u root -p

-bash: mysql: 未找到命令

[root@slave bin]# cd

[root@slave ~]# mysql

[root@slave ~]# mysql -u root -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@slave ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.31

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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 WITH mysql_native_password BY 'mysql';

Query OK, 0 rows affected (0.02 sec)

mysql> \q

Bye

[root@slave ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit

Bye

[root@slave ~]# init 0