MYSQL更改root password时遇到Access Denied的解决办法

今天在公司虚拟机上装MYSQL之后需要修改root password,然而遇到这样的错误:

Access denied for user 'root'@'localhost' (using password:YES)

后来在网上搜了下,找到如下解决办法,测试可用。

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

原文地址:https://www.cnblogs.com/chrischeng/p/3822490.html