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

遠程鏈接數據時,報如下提示:php

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

緣由是數據庫服務不容許遠程登陸,沒有受權致使,解決方法以下:web

登錄mysql數據庫:sql

mysql –uroot –p123456數據庫

建立並受權一個專用的數據庫wordpress用於存放blog數據:ide

create database wordpress;wordpress

show database like ‘wordpress’;測試

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

注:當數據庫和php服務不在同一臺機器上,可執行以下命令受權spa

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)

測試效果:

 

相關文章
相關標籤/搜索