[root@stw mysql]# chown -R mysql.mysql /usr/local/mysql/[root@stw local]# ll -d /usr/local/mysql
lrwxrwxrwx 1 mysql mysql 36 Sep 19 11:01 /usr/local/mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/[root@stw local]# cd mysql[root@stw mysql]# ll
total 272
drwxr-xr-x 2 mysql mysql 4096 Sep 19 11:00 bin
drwxr-xr-x 2 mysql mysql 55 Sep 19 11:00 docs
drwxr-xr-x 3 mysql mysql 4096 Sep 19 11:00 include
drwxr-xr-x 5 mysql mysql 230 Sep 19 11:00 lib
-rw-r--r-- 1 mysql mysql 259253 Nov 30 2021 LICENSE
drwxr-xr-x 4 mysql mysql 30 Sep 19 11:00 man
-rw-r--r-- 1 mysql mysql 566 Nov 30 2021 README
drwxr-xr-x 28 mysql mysql 4096 Sep 19 11:00 share
drwxr-xr-x 2 mysql mysql 90 Sep 19 11:00 support-files
[root@stw ~]# mkdir -p /opt/data/{3306..3308}[root@stw ~]# ls /opt/data
3306 3307 3308
[root@stw ~]# chown -R mysql.mysql /opt/data/[root@stw ~]# ll -d /opt/data
drwxr-xr-x 5 mysql mysql 42 Sep 19 11:15 /opt/data[root@stw ~]# cd /opt/data[root@stw data]# ll
total 0
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3306
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3307
drwxr-xr-x 2 mysql mysql 6 Sep 19 11:15 3308
8、初始化3306实例(并将生成的密码重定向到3306文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2025-09-19T03:19:53.313330Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:19:53.734715Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:19:53.802030Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:19:53.904191Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 82ba4984-9507-11f0-a284-000c29b9a32a.
2025-09-19T03:19:53.905685Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:19:55.877239Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:19:55.877261Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:19:55.880916Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:19:56.492273Z 1 [Note] A temporary password is generated for root@localhost: shKBQpf:I7Ug
[root@stw ~]# echo 'shKBQpf:I7Ug' > 3306[root@stw ~]# cat 3306
shKBQpf:I7Ug
9、初始化3307实例(并将生成的密码重定向到3307文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2025-09-19T03:22:14.389157Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:22:14.953903Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:22:15.074010Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:22:15.176918Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d6eecbce-9507-11f0-a725-000c29b9a32a.
2025-09-19T03:22:15.178270Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:22:16.094502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:16.094525Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:16.095841Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:22:16.843750Z 1 [Note] A temporary password is generated for root@localhost: yMk&Jas5!AD0
[root@stw ~]# echo 'yMk&Jas5!AD0' > 3307[root@stw ~]# cat 3307
yMk&Jas5!AD0
10、初始化3308实例(并将生成的密码重定向到3308文件中)
[root@stw ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2025-09-19T03:22:50.600213Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-19T03:22:51.120379Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-19T03:22:51.204391Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-19T03:22:51.287530Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ec74d6bd-9507-11f0-aa7d-000c29b9a32a.
2025-09-19T03:22:51.289424Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-19T03:22:52.438302Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:52.438335Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-19T03:22:52.445813Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-19T03:22:52.813578Z 1 [Note] A temporary password is generated for root@localhost: 1Rvd&58hkzrj
[root@stw ~]# echo '1Rvd&58hkzrj' > 3308[root@stw ~]# cat 3308
1Rvd&58hkzrj
[root@stw ~]# cat 3306
shKBQpf:I7Ug
[root@stw ~]# mysql -uroot -p'shKBQpf:I7Ug' -S /tmp/mysql3306.sock
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 2
Server version: 5.7.37Copyright (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> set password = password('redhat');
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> exit
Bye
[root@stw ~]# mysql -uroot -p'redhat' -S /tmp/mysql3306.sock
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 3
Server version: 5.7.37 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> flush privileges;
Query OK, 0 rows affected (0.01 sec)
3307:
[root@stw ~]# mysql -uroot -p'yMk&Jas5!AD0' -S /tmp/mysql3307.sock -e 'set password = password("redhat");' --connect-expired-password//--connect-expired-password 连接失效的密码
mysql: [Warning]Using a password on the command line interface can be insecure.[root@stw ~]# mysql -uroot -predhat -S /tmp/mysql3307.sock
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 3
Server version: 5.7.37 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> flush privileges;
Query OK, 0 rows affected (0.01 sec)
3308:
[root@stw ~]# cat 3308
1Rvd&58hkzrj
[root@stw ~]# mysql -uroot -p'1Rvd&58hkzrj' -S /tmp/mysql3308.sock -e 'set password = password("redhat");' --connect-expired-password
mysql: [Warning]Using a password on the command line interface can be insecure.[root@stw ~]# mysql -uroot -predhat -S /tmp/mysql3308.sock
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 3
Server version: 5.7.37 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> flush privileges;
Query OK, 0 rows affected (0.01 sec)