[root@cc01 ~]# cat /var/my.cnf cat: /var/my.cnf: 没有那个文件或目录 [root@cc01 ~]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld] skip-grant-tables # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove the leading "# " to disable binary logging # Binary logging captures changes between backups and is enabled by # default. It's default setting is log_bin=binlog # disable_log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M # # Remove leading # to revert to previous value for default_authentication_plugin, # this will increase compatibility with older clients. For background, see: # https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin # default-authentication-plugin=mysql_native_password
[root@cc01 ~]# cat /var/log/mysqld.log|grep password 2023-06-25T04:13:06.877387Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 8r?eVhBzesGK 2023-06-25T15:27:18.813616Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9c9K#HOkc%s3
这里肯定是取后面一个最新的临时密码
4、修改密码
mysql -uroot -p原密码 password 新密码(新密码必须为字母加数字)
如果之前设置了密码策略,这里新密码不做要求
1 2 3 4 5 6 7 8 9
[root@cc01 ~]# mysql -uroot -p9c9K#HOkc%s3 password 12345678 mysql: [Warning] Using a password on the command line interface can be insecure. mysql Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2023, 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. ·······
5、使用新密码进入:mysql -uroot -p即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@cc01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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 '@admin123A'; <------------设置符合安全策略的密码 Query OK, 0 rows affected (0.01 sec)
mysql> exit Bye [root@cc01 ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@cc01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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 global validate_password.policy=LOW; <---------------------- 设置安全策略等级为low Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=6; <---------------------- 设置长度至少为6位 Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%'; <---------------------- 查看密码安全策略表 +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password.check_user_name | ON | | validate_password.dictionary_file | | | validate_password.length | 6 | | validate_password.mixed_case_count | 1 | | validate_password.number_count | 1 | | validate_password.policy | LOW | | validate_password.special_char_count | 1 | +--------------------------------------+-------+ 7 rows in set (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678'; <-------------更改成简单密码成功 Query OK, 0 rows affected (0.01 sec)
mysql> exit Bye [root@cc01 ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) [root@cc01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, 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.