修改密碼
1.查看初始密碼
grep 'temporary password' /var/log/mysqld.log
2.連接 MySQL, 輸入下面代碼, 回車后輸入上面密碼
mysql -uroot -p
3.選數據庫
use mysql;
4.將authentication_string置空
update user set authentication_string='' where user='root';
注:在mysql8.0以上版本,
update mysql.user set password='newpassword' where user='root';
update mysql.user set password=PASSWORD('newpassword') where User='root';
這兩條命令已經不起作用了
5.修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼';
會出現報錯如下:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
這個其實與validate_password_policy的值有關
有以下取值:
| Policy | Tests Performe(要求) |
|---|---|
| 0 or LOW | Length |
| 1 or MEDIUM | numeric, lowercase/uppercase, and special characters |
| 2 or STRONG | Length; numeric, lowercase/uppercase, and special characters |
默認是1,即MEDIUM,所以剛開始設置的密碼必須符合長度,且必須含有數字,小寫或大寫字母,特殊字符。
有時候,只是為了自己測試,不想密碼設置得那么復雜,譬如說,我只想設置root的密碼為123123.
這是時候,Wimbledon可以在第一次使用進入數據庫的時候修改幾個全局變量就行,或者再次跳過權限表進入到數據庫!
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 | ##密碼的最小長度,改成6
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM | #這個改成0,就可以接受簡單的密碼
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
#修改全局變量
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 in set (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123123'; #重新修改密碼,不會再有錯誤!
Query OK, 0 rows affected (0.01 sec)
from:
