安裝
一行命令就可以
sudo apt install mysql-server
問題
所有問題解決都需要先切換到系統root用戶 或者sudo使用root用戶權限
use mysql;
select user, plugin from user;
在mysql中執行上面兩行
如果root對應的 plugin 是 auth_socket 就按照 問題三 解決
如果是 mysql_native_password 就按照 問題一二 解決
問題一
ruoke@ruoke:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’
解決:
use mysql;
#通常這一步會出現問題二錯誤
update user set authentication_string=password("你的密碼") where user="root";
flush privileges;
問題二
密碼策略問題異常信息:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解決:
#查看mysql密碼策略
SHOW VARIABLES LIKE 'validate_password%';
#設置 validate_password_policy 密碼驗證強度 的全局參數爲 LOW
set global validate_password_policy=LOW;
#設置密碼長度 我默認使用 root 爲密碼 所以設置成4
set global validate_password_length=4;
#設置密碼
update user set authentication_string=password("你的密碼") where user="root";
bash記錄:
root@ruoke:/etc/mysql# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> update user set authentication_string=password("root~") where user="root";
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=password("root") where user="root";
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| 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 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> update user set authentication_string=password("root") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
問題三
update user set authentication_string=password("你的密碼"),plugin='mysql_native_password' where user='root';
如果還是出錯
ERROR 1819 (HY000): Your password does not satisfy the current policy require
就再次
SHOW VARIABLES LIKE 'validate_password%';
查看自己最短的密碼是不是設置好了
再次執行問題二的解決辦法就可以了
可以多試試
flush privileges;
沒準是玄學問題
問題四
遠程用戶不允許鏈接
ERROR 1130 (HY000): Host ‘192.168.43.38’ is not allowed to connect to this MySQL server
解決:
use mysql;
update user set host = '%' where user = 'root';
exit;
然後
service mysql restart
就可以了
至此基本所有情況都能解決了 QWQ 有問題歡迎討論
參考博客:
https://blog.csdn.net/ls0111/article/details/75113970
https://www.cnblogs.com/cpl9412290130/p/9583868.html