報錯:Host is not allowed to connect to this MySQL server解決方法
先說說這個錯誤,其實就是我們的MySQL不允許遠程登錄,所以遠程登錄失敗了,解決方法如下:
在裝有MySQL的機器上登錄MySQL mysql -u root -p密碼
[root@localhost ~]# mysql -u root -p
Enter password:
執行use mysql;
mysql > use mysql;
執行update user set host = '%' where user = 'root';這一句執行完可能會報錯,不用管它。
執行FLUSH PRIVILEGES;
全部命令
[root@localhost ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.11 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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> 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 host = '%' where user = 'root'; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql>
經過上面4步,就可以解決這個問題了。
注: 第四步是刷新MySQL的權限相關表,一定不要忘了,我第一次的時候沒有執行第四步,結果一直不成功,最后才找到這個原因。
如果以上還不能解決問題,可以嘗試
報錯:authentication plugin 'caching_sha2_password
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
以上兩步驟基本可以解決 mysql對外訪問了