2019独角兽企业重金招聘Python工程师标准>>>
如图报错如下:
谷歌了一下之后,原来是在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