mysql局域网访问设置

局域网连接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;

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值