修改mysql初始密码

查看当前MySQL登录密码

[root@liwenjing mysql]# grep password /var/log/mysqld.log 
2022-09-22T19:20:12.368849Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: mmxuyPx%+2hC
当前登录密码为:mmxuyPx%+2hC

执行mysql -u root -p命令登录mysql数据库,其中-u指定用户,-p指定密码
[root@liwenjing mysql]# 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.30

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>

看到mysql>标识符标识成功登录。

修改初始密码
[root@liwenjing mysql]# mysql_secure_installation
Redhat@123456
重新登录数据库
[root@liwenjing mysql]# mysql -uroot -p

修改初始密码(若想改为弱密码),查看密码强度
SHOW variables LIKE 'validate_password%';
mysql> SHOW variables LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
| validate_password_check_user_name    | ON     |
| validate_password_dictionary_file    |        |
| validate_password_length             | 4      |
| validate_password_mixed_case_count   | 1      |
| validate_password_number_count       | 1      |
| validate_password_policy             | LOW    |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

将密码验证策略改为LOW,密码长度4位以上
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=4;
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             | 4     |
| validate_password.mixed_case_count   | 1     |
| validate_password.number_count       | 1     |
| validate_password.policy             | LOW   |
| validate_password.special_char_count | 1     |
| validate_password_check_user_name    | ON    |
| validate_password_dictionary_file    |       |
| validate_password_length             | 4     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
14 rows in set (0.00 sec)

将mysql登录密码设置为redhat

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'redhat';

退出当前登录
mysql> exit
Bye

你可能感兴趣的:(数据库,mysql,java)