1. 程式人生 > >ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.111.133' (111)解決辦法

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

如圖報錯如下:

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

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 #這裡預設監聽本地localhost

如果要讓mysql監聽到其他的地址,可以將bind-address = 127.0.0.1註釋掉。

或者將bind-address = 0.0.0.0監聽所有的地址

遮蔽掉之後再次執行程式碼又出現:mysql -h 192.168.111.133 -uroot -p

Enter password:

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

如圖:

解決方法:

如果想讓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