连接远程数据库 error:1130

原文地址: https://www.cnblogs.com/peachlht/p/5888586.html

windows下本地或者远程连接MYSQL数据库,报1130错误的解决方法

重装MySQL,由于不知道重装之前的root密码,使用重装之后的密码连接Mysql数据,总报 ERROR 1130: host 'localhost' not allowed to connect to this MySQLserver,不能连接数据库,猜测用户权限和密码的问题。

1、用root用户登录mysql数据库

(1)停止MySQL服务,执行net stop mysql;

(2)在mysql的安装路径下找到配置文件my.ini,

   找到[mysqld]
   输入:skip-grant-tables,保存

(3)重启mysql服务,net start mysql;

(4)执行mysql -uroot -p,回车,再回车,即可进入mysql数据库;

2、在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'。

mysql>use mysql;

mysql>select host,user,password from user;

mysql>update user set host = '%' where user ='root';

mysql>flush privileges;    #刷新用户权限表

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

3、插入本地登录的用户

mysql>insert into user values('localhost', 'root', '', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y','','','','',0,0,0,0,'','');

此时本地连接的用户localhost密码为空

4、修改root密码

(1)用set password 方式修改root密码遇到错误ERROR 1290 (HY000)

mysql> set password for root@'localhost'=PASSWORD('12345');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
cute this statement

注意:以skip-grant-tables方式启动mysql后,不能用直接用set password的方式修改root密码,须注释skip-grant-tables, 然后重启服务,连接数据库修改密码

(2)用update方式修改root密码正常

mysql> update user set password=password("123") where user="root";

mysql>flush privileges; 

 (3)不连接数据库,直接在cmd下修改密码

mysqladmin -uroot -p旧密码 password 新密码,此种方式修改密码也不能在以“skip-grant-tables“方式启动mysql后进行

如:mysqladmin -uroot -p123456 password 1234

5、退出MySQL,在配置文件中注释:skip-grant-tables,重启mysql服务

6、本地重新连接mysql数据库,输入修改后的密码,连接成功

猜你喜欢

转载自blog.csdn.net/weixin_41917449/article/details/81081520
今日推荐