[转]Mysql 登录提示"ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)"

阿里云,一直提示 “ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)”。

不用怀疑!是密码不对,如果密码确认输入正确,那么肯定是有人改过root密码了。

怎么重置密码呢?

1,执行 vim /etc/mysql/my.cnf   ,打开文件后,找到mysqld关键字,在mysqld下面添加skip-grant-tables,保存退出

2,执行 service mysql restart,重启之后,再尝试登陆mysql,遇到需要输入密码,直接回车

3,执行 use mysql

4,执行 update user set password=PASSWORD("你的新密码") where user="root";   这是mysql的执行语句,所以记得末尾加上;号

5,执行 exit ,退出mysql

6,执行 vim /etc/mysql/my.cnf,打开文件后, 把刚才添加的 skip-grant-tables 删掉,保存退出

7,执行 service mysql restart。

重启之后,就可以用刚才设置的密码登录mysql了。



作者:qhcmler
链接:https://www.jianshu.com/p/7e9cb8fe4e6b

原文地址:https://www.cnblogs.com/fe-cherrydlh/p/10599665.html