MySQL:忘记root密码:修订间差异

来自WHY42
imported>Soleverlee
无编辑摘要
imported>Soleverlee
无编辑摘要
 
第20行: 第20行:
flush privileges;
flush privileges;
</source>
</source>
 
如果提示错误的话:
<pre>
You must reset your password using ALTER USER statement before executing this statement.
</pre>
需要修改密码:
<source lang="bash">
mysql -uroot -p
> set password=password('123456...')
</source>
[[Category:Database]]
[[Category:Database]]

2017年5月11日 (四) 09:17的最新版本

首先停止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...')