- 关闭mysql服务
/etc/init.d/mysql stop
- 使用安全模式 --skip-grant-tables的参数启动mysql
mysqld_safe --skip-grant-tables
- 再打开一个新shell,设置新的密码
shell> mysql
mysql> UPDATE mysql.user SET password=PASSWORD('newpwd') WHERE user='root';
mysql> FLUSH PRIVILEGES;
- 停止mysql server,用正常的模式启动
/etc/init.d/mysql stop
/etc/init.d/mysql start
-----------------------------------
/etc/init.d/mysql restart
- OK,使用新设置的密码登录
mysql -u root -h 127.0.0.1 -p