Mysql ERROR 1045 (28000)

昨天yum update更新了一票东西,今天用mysql -u root -p登录mysql的时候居然出现ERROR 1045 (28000):

[root@master /etc]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决方法:

vim /etc/my.cnf
在[mysqld]这个条目下加入
skip-grant-tables
保存退出后重启mysql
/etc/init.d/mysqld restart

这时候mysql -u root -p就可以用密码登录了,不会出现ERROR 1045 (28000),但很多操作都会受限制,因为我们不能grant。按下面的流程走:

mysql> use mysql;
Database changed
mysql> update user set password=password("新密码") where user="root";
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

改好之后,再修改一下/etc/my.cnf这个文件,把我们刚才加入的"skip-grant-tables"这行删除,保存退出再重启mysql就可以了。难道以后每次更新mysql都会ERROR 1045 (28000)吗?

LAMP

Email: i at onepx dot com || QQ: ⑧九零三④幺 || 微信: onepxcom
©2023 一像素 蜀ICP备13026576号-2 网站地图