第一: 关闭数据库
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
第二: 启动数据库到维护模式(忘记密码)
[root@db01 ~]# mysqld_safe --skip-grant-tables --skip-networking &
第三: 登录并修改密码
[root@db01 ~]#mysql
mysql> alter user root@'localhost' identified by '123';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
mysql> alter user root@'localhost' identified by '123';
Query OK, 0 rows affected (0.01 sec)
第四:重启数据库到正常模式
[root@db01 ~]# service mysqld restart
第五:登录
mysql -uroot -p123