ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.111.133' (111)解決辦法

如圖報錯以下:html

谷歌了一下以後,原來是在mysql的my.cnf中有下面一段代碼:mysql

Instead of skip-networking the default is now to listen only on

localhost which is more compatible and is not less secure.

bind-address = 127.0.0.1 #這裏默認監聽本地localhostsql

若是要讓mysql監聽到其餘的地址,能夠將bind-address = 127.0.0.1註釋掉。數據庫

或者將bind-address = 0.0.0.0監聽全部的地址less

屏蔽掉以後再次運行代碼又出現:mysql -h 192.168.111.133 -uroot -pide

Enter password:測試

ERROR 1130 (HY000): Host '192.168.111.133' is not allowed to connect to this MySQL serverthis

如圖:3d

解決方法:code

若是想讓192.168.10.83可以鏈接到本地的這個數據庫,要讓數據庫給其分配權限,登陸mysql,執行:(username 和 password是登陸mysql的用戶名和密碼)

GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.0.111' IDENTIFIED BY 'password' WITH GRANT OPTION;

若是要想全部的外部ip地址都可以訪問使用mysql,能夠執行下面:

GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

以後執行刷新數據庫:

flush privileges;

知識點:

1:那麼咱們來建立一個測試帳號test,授予全局層級的權限。以下所示:

mysql> grant select,insert on . to test@'%' identified by 'test';

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql>

mysql> show grants for test;

+--------------------------------------------------------------------------------------------------------------+

| Grants for test@%
| +--------------------------------------------------------------------------------------------------------------+

| GRANT SELECT, INSERT ON . TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |

+--------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql> select * from mysql.user where user='test'\G;

2:那麼咱們來建立一個測試帳號test,授予數據庫層級的權限。以下所示:

mysql> drop user test;

Query OK, 0 rows affected (0.00 sec)

mysql> grant select,insert,update,delete on MyDB.* to test@'%' identified by 'test';

Query OK, 0 rows affected (0.01 sec)

mysql>

mysql> select * from mysql.user where user='test'\G; --能夠看到無任何受權。

mysql> select * from mysql.db where user='test'\G;

mysql>

mysql> show grants for test;

+-----------------------------------------------------------------------------------------------------+

| Grants for test@% |

+-----------------------------------------------------------------------------------------------------+

| GRANT USAGE ON . TO 'test'@'%' IDENTIFIED BY PASSWORD '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |

| GRANT SELECT, INSERT, UPDATE, DELETE ON MyDB.* TO 'test'@'%' |

+-----------------------------------------------------------------------------------------------------+

2 rows in set (0.00 sec)

mysql> http://www.cnblogs.com/wangchaoyuana/p/7545419.html

相關文章
相關標籤/搜索