grep 'temporary password'/var/log/mysqld.log
mysql -uroot -p
use mysql;
update user set authentication_string='' where user='root';
Note: In mysql8.0 and above,
update mysql.user set password='newpassword' where user='root';
update mysql.user set password=PASSWORD('newpassword') where User='root';
These two commands no longer work
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
There will be an error as follows:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
This is actually related to the value of validate_password_policy
The following values are available:
Policy | Tests Performe (Required) |
---|---|
0 or LOW | Length |
1 or MEDIUM | numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters |
The default is 1, which is MEDIUM, so the password set at the beginning must meet the length, and must contain numbers, lowercase or uppercase letters, and special characters.
Sometimes, I just want to test myself and don’t want the password to be so complicated. For example, I just want to set the root password to 123123.
This is the time, Wimbledon can modify a few global variables when using it to enter the database for the first time, or skip the permission table to enter the database again!
mysql> show variables like "%validate%";+--------------------------------------+--------+| Variable_name | Value |+--------------------------------------+--------+| query_cache_wlock_invalidate | OFF || validate_password_check_user_name | OFF || validate_password_dictionary_file ||| validate_password_length |8| ##The minimum length of the password, change to 6| validate_password_mixed_case_count |1|| validate_password_number_count |1|| validate_password_policy | MEDIUM | #Change this to 0, you can accept a simple password
| validate_password_special_char_count |1|+--------------------------------------+--------+
# Modify global variables
mysql>set global validate_password_length=6;
Query OK,0 rows affected(0.00 sec)
mysql>set global validate_password_policy=0;
Query OK,0 rows affected(0.00 sec)
mysql> show variables like "%validate%";+--------------------------------------+-------+| Variable_name | Value |+--------------------------------------+-------+| query_cache_wlock_invalidate | OFF || validate_password_check_user_name | OFF || 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|+--------------------------------------+-------+8 rows inset(0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123123'; #Change the password again, there will be no more mistakes!
Query OK,0 rows affected(0.01 sec)
from:
https://blog.csdn.net/ssiyla/article/details/82931439
https://www.cnblogs.com/mzxiaoze/p/10413399.html
Recommended Posts