局域网连接mysql报错: 

ERROR 1130: Host '192.168.0.220' is not allowed to connect to this MySQL server

解决方法:


可能是帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" 或添加一个用户为“%”  。    

想让局域网中的所有机器都能连接MySQL数据库,首先要给MySQL开启远程连接的功能,在MySQL服务器控制台上执行MySQL命令:

grant all privileges on *.* to root@"%" identified by 'abc' with grant option;  
flush privileges;

 

其中上面两行代码的意思是给从任意ip地址连接的用户名为root,密码为abc的用户赋予所有的权限。其中的"%"为任意的ip地址,如果想设为特定的值也可以设定为特定的值(以通配符%的内容增加主机/IP地址,也可以直接增加IP地址)。

做完这些之后,局域网内的mysql服务器可以访问了。

实例1:

-- 创建用户 ---单个数据库授权 
create user 'testone'@'localhost' identified by '123';
grant all privileges on testone.* to testone ;


-- 创建用户2
create user 'testtwo'@'localhost' identified by '123';

grant all privileges on *.*  to testtwo@'localhost';

grant all privileges on *.*  to testtwo@'localhost';

-- 授予用户 远程访问 
grant all privileges on *.*  to wlliuxue@'%' identified by '123' with grant option;
flush privileges;

grant all privileges on *.*  to testone@'192.168.1.126' identified by '123' with grant option;
flush privileges;


grant all privileges on *.* to root@'%' identified by '123' with grant option;  
flush privileges;

本文转载:CSDN博客