当前位置: 代码迷 >> 综合 >> mysql远程连接报错 : 1130-host ... is not allowed to connect to this MySql server
  详细解决方案

mysql远程连接报错 : 1130-host ... is not allowed to connect to this MySql server

热度:49   发布时间:2023-11-17 21:59:02.0

解决办法:

一、改表法(推荐使用)

可能是帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 mysql 数据库里的 user”表里的 host”项,把localhost改成%。

shell>mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root'  and host='localhost';
mysql>select host, user from user;
mysql>flush privileges;

二、授权法

1、用户名为myuser使用密码mypassword从任何主机连接到mysql服务器:

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

2、用户名为myuser从ip为192.168.238.145的主机连接到mysql服务器,并使用mypassword作为密码连接:

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

3、用户名为myuser从ip为192.168.1.6的主机连接到mysql服务器的mydb数据库,并使用mypassword作为密码:

GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH   PRIVILEGES;
  相关解决方案