解決遠程連接數據庫:Host is not allowed to connect to this MySQL server


遠程連接數據時,報以下提示:

Host 'web1' is not allowed to connect to this MySQL server

原因是數據庫服務不允許遠程登錄,沒有授權導致,解決方法如下:

登陸mysql數據庫:

mysql –uroot –p123456

創建並授權一個專用的數據庫wordpress用於存放blog數據:

create database wordpress;

show database like ‘wordpress’;

grant all on worpress.* to worpress@'localhost' identified by '123456';

注:當數據庫和php服務不在同一台機器上,可執行如下命令授權

grant all on wordpress.* to wordpress@’192.168.0.%’ identified by ‘123456’;

刷新權限,使得創建的用戶生效:

flush privileges;   

查看用戶對應的權限:

select user,host from mysql.user where user='wordpress';  

[root@mysql ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on wordpress.* to wordpress@'192.168.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user where user='wordpress';
+-----------+-------------+
| user      | host        |
+-----------+-------------+
| wordpress | 192.168.0.% |
+-----------+-------------+
1 row in set (0.00 sec)

測試效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM