如图报错以下:html
谷歌了一下以后,原来是在mysql的my.cnf中有下面一段代码:mysql
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)