# service mysql stop
# service mysqlstart --skip-grant-tables //跳过授权表启动MySQL服务程序
# mysql -u root //不需要密码登录
mysql> update mysql.user set password=password(‘123456‘) where host="localhost"; //通过修改mysql库中user表的相关记录重置密码
Query OK, 0 rows affected (0.38 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> flush privileges; //刷新授权表
Query OK, 0 rows affected (0.14 sec)
# service mysql restart //重启服务
# mysql -hlocalhost -uroot -p123456 //使用新密码登录
mysql>