当前位置: > 数据库 > MySQL >

解决mysql操作1045错误,1153错误和1130错误

时间:2019-02-18 17:13来源:未知 作者:IT
一、ERROR 1045 (28000): Access denied for user 'root'@'119.29.194.112' (using password: YES)
远程连接数据,发现报1045错误,原因是本地的ip没有访问远程数据库的权限。

解决方法:

1、进入数据库;

2、查看是否有权限:

use mysql;
select user,password,host from user;    #查看本地ip是否有权限
可以看到host列中只有localhost主机,没有119.29.194.112,所以root用户在119.29.194.112主机上没远程访问数据库的权限,因此没有我们需要将119.29.194.112也添加到这里。

3、授权:

grant all privileges on *.* to root@"119.29.194.112" identified by "密码";    #授予指定ip主机对数据库的所有权限,包括远程访问权限
flush privileges;    #授权立即生效
grant all privileges on *.* to root@"%" identified by "密码";    #如果想要root用户在任意主机都有远程操作数据库的所有权限,则将ip换为%
4、现在再次查看是否拥有权限,输入:select user,host from user; 可以看到host列已经有了我们刚才添加主机ip或者%,说明已经有访问的权限了;再次远程连接,就能正常连接上数据库了。




二、ERROR 1153 : Got a packet bigger than 'max_allowed_packet' bytes。
导入数据库脚本文件进行建表的时候,发现表导入失败,查看日志,报了1153 ERROE,原因是数据库默认对导入的数据大小做了限制,因此我们可以通过修改数据库的该变量配置数值。

1.临时修改:

mysql>set global max_allowed_packet=524288000;     #修改为512M
2.长久修改:修改my.cnf(centos下路径为/etc/my.cnf。windows下为my.ini),需重启mysql。

在 [MySQLd] 部分添加一句(如果存在,调整其值就可以):
max_allowed_packet=256M (根据实际情况调整数值)
可通过命令查看是否修改成功:

show VARIABLES like '%max_allowed_packet%’;




三、ERROR 1130: host 'localhost' not allowed to connect to this MySQL server。

由于不小心将mysql数据库本地连接的root删除了,之后连接MySQL,一直报ERROR 1130: host 'localhost' not allowed to connect to this MySQL server。

解决方法:

1.停止MySQL服务,打开cmd命令行,执行net stop mysql;

2.在mysql的安装路径下,找到配置文件my.ini,找到[mysqld]这一栏,在这部分最下面加入skip-grant-tables,顾名思义,就是在启动mysql时不启动grant-tables授权表,保存。保存的时候可能会因为权限不够出现拒绝保存的情况,这时可以右键my.ini文件-->属性-->安全-->编辑,修改文件的读写权限。

3.重启mysql服务,net start mysql;

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

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

mysql>use mysql;

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

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

 

6.插入本地登录的用户

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密码为空

 

7.修改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 execute 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



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

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

 


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容