sudo service mysql stop
sudo mysqld_safe --skip-grant-table&
mysql
use mysql;
update user set password = password('yourpasswd') where user = 'root';
flush privileges;
重启登录后,如果提示:You must SET PASSWORD before executing this statement
解决:
mysql> SET PASSWORD = PASSWORD('123456');