MySQL安装在192.168.137.100 Ubuntu 12.04 LTS
客户端在 192.168.137.200 win7
客户端希望访问MySQL数据库,会出现如下错误“ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.137.100' (10061)”
C:\>mysql -h 192.168.137.100 -u root -p Enter password: **** ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.137.100' (10061)
这是因为缺省情况下MySQL是只允许本机登录的。修改MySQL的配置文件位于/etc/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 <---注释掉这一行
C:\>mysql -h 192.168.137.100 -u root -p Enter password: **** ERROR 1130 (HY000): Host 'abbuggy-PC.mshome.net' is not allowed to connect to this MySQL server
有两种方法,直接修改表内容或者通过授权命令
将 "mysql" 数据库的 "user" 表里的 "host" 字段,从"localhost"改为"%"。%相当于所有地址,也可以指定某些地址。
~$ mysql -uroot -proot >use mysql; >update user set host = '%' where user = 'root'>SELECT host, user FROM user;
例如,你想用root从任何主机连接到mysql服务器的话。
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.137.100' IDENTIFIED BY 'root' WITH GRANT OPTION;
问题得到解决