SQL Error (1130): Host '192.168.1.126' is not allowed to connect to this MySQL server

Connecting to the MYSQL database through HeidiSQL reports an error:
 SQL Error (1130): Host '192.168.1.126' is not allowed to connect to this MySQL server
indicates that the connected user account does not have permission to connect remotely and can only log in on the local machine (localhost).
You need to change the host item in the user table in the mysql database and change the name to localhost.
First, log in to the Mysql server according to the following steps. To log in
to mysql, you need to switch to the mysql bin directory under dos, and perform the following operations:
mysql>use mysql;

mysql>update user set host = '%'  where user ='root';
MariaDB [mysql]> update user set host = '%' where host = 'localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

mysql>flush privileges;
mysql> select host, user from user;
mysql>quit
OK. The remote connection is successful!


MYSQL setting remote account login summary

1. ERROR 2003 (HY00 1

2. ERROR 1045 (28000): Access denied for user 'test'@'x.x.x.x' (using password: NO) 1

3.  Retrieve ROOT password and set remote login  2

4. RROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 2

5. ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 3

6.  Set the user's remote host connection permission 4

7.  Set permissions for users and libraries 4



为了给MYSQL用户设置一个远程连接权限,经历了很多曲折..特此纪录下来..先是玉到了2003错误

ERROR 2003 (HY00

原因是MySQL考虑到安全因素,默认配置只让从本地登录

打开 /etc/mysql/my.cnf 文件,找到 bind-address = 127.0.0.1 修改为 bind-address = 0.0.0.0

重启mysql : sudo /etc/init.d/mysql restart

再次连接,发生错误 1045

ERROR 1045 (28000): Access denied for user 'test'@'x.x.x.x' (using password: NO)

A: 原因是没有给登录用户名设置远程主机登录的权限。还有种可能是你需要重设下密码....可能是授权操作引起这种后遗症..

在本地用 root 登录: mysql -u root -p

修改 MySQL 数据库中 user 表中 对应用户名的 Host 字段,将 localhost 改为 %

use mysql;

update user set Host = '%' where User = 'username';

给这个设置权限需要ROOT用户登录才行.可惜ROOT密码不记得了.

取回ROOT密码并设置远程登录


mysqld_safe --skip-grant-tables &

mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

设置 ROOT 远程连接  update user set host = '%'   where user='root';

查看进程,可看到MYSQLD_SAFEMYSQL进程,此时MYSQL可正常使用,不过查看参数,可看到--skip-grant-tab

输入mysqld_safe命令行,要立马输入mysql -u root mysql,不得有误..或者新开一个窗口也可.

执行UPDATE时出现1062错误

RROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 

如果执行update语句时出现ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 错误,说明有多个ROOT用户纪录在USER表中了.

需要select host from user where user = 'root';

查看一下host是否已经有了%这个值,有了就可以了.

mysql> select host,user from user where user='root';

+-----------------------+------+

| host                  | user |

+-----------------------+------+

| %                     | root |

| 127.0.0.1             | root |

| ::1                   | root |

| localhost.localdomain | root |

然后用ROOT用户登录更改用户账户的远程连接权限时.出现提示:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

是因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的''@'localhost'可以看出来,于是解决办法见

先关闭MYSQL进程..

然后

   # mysqld_safe --skip-grant-table

   屏幕出现: Starting demo from .....

此时要记得,紧接着输入

   # mysql -u root mysql

   mysql> delete from user where USER='';

   mysql> FLUSH PRIVILEGES; 

 

如果出现  Starting demo from .. ..先输入其它命令,再用mysql -u root mysql .它又会出现这个错误了.

然后KILLMYSQL进程,..重启正常的进程..

设置用户远程主机连接权限

update user set host = '%'  where user='fanzkcom_fanzk'; 

FLUSH PRIVILEGES; 

但是在实际连接中,虽然可以连接,但是去没有所在库的权限,.

只好接下来设置权限

设置用户与库的权限

grant all privileges on fanzkcom_fanzk.* to fanzkcom_fanzk@'%' identified by '1234';

FLUSH PRIVILEGES; 

百分号两边要有单引号,否则语法错误

然后连接时,竟然提示1045 错误了.,,想了半天,还是重设下密码试下.

 update mysql.user set password=password('XXX') where User="fanzkcom_fanzk"  

 flush privileges;




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578253&siteId=291194637