今天遇到以下错误: error 1045 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('123456') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

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