跳转到内容

欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。

MySQL:忘记root密码

来自WHY42

首先停止mysql

service mysql stop

然后以安全模式启动mysql在后台运行:

mysqld_safe --skip-grant-tables &

然后就可以以root登录到mysql服务器上

mysql -u root
use mysql

修改MySQL的root密码:

update user set password=PASSWORD('123456') where User='root';

#MySQL 5.7
update user set authentication_string=password('123456') where user='root';
flush privileges;

如果提示错误的话:

You must reset your password using ALTER USER statement before executing this statement.

需要修改密码:

mysql -uroot -p
> set password=password('123456...')