1130-host ... is not allowed to connect to this MySql server

一:问题描述

当远程连接数据库的时候,报错:

1130-host ... is not allowed to connect to this MySql server_第1张图片

二:出错原因

你要远程连接的数据库不允许你这台机器访问。

三:解决办法

有两种方式可以解决:

被远程访问的机器上做以下操作:

1:update user表

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
 
mysql> update user set host='%' where user ='root';
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

2:赋予权限

例如,你想让该服务器的所有数据库可以被任何主机通过用户myuser/mypassword进行远程连接。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;

如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器的dk数据库,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH   PRIVILEGES;


示例:允许所有主机可以访问该服务器下的所有数据库,以用户root就行访问:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed

mysql> grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.03 sec)
 
mysql> select host,user from user;
+------------+------+
| host       | user |
+------------+------+
| %          | root |
| 127.0.0.1  | root |
| ::1        | root |
| target\_pc | root |
+------------+------+
4 rows in set (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

--本篇文章参考自:http://www.cnblogs.com/xyzdw/archive/2011/08/11/2135227.html



你可能感兴趣的:(1130-host ... is not allowed to connect to this MySql server)