mysql忘记密码

  • A+
所属分类:Mysql

系统环境:Centos 7

1.停止mysql服务

systemctl stop mysql

2.以安全模式启动

mysqld_safe --skip-grant-table &

3.登录数据库

mysql -u root

4.更改密码

UPDATE user SET password=PASSWORD("new password") WHERE user='root';
flush privileges;

5.修改完以后关闭mysql,正常启动

 另一个方法,解决安全模式root登录问题

1.关闭mysql

# service mysqld stop

2.屏蔽权限

# mysqld_safe --skip-grant-table

屏幕出现: Starting demo from .....

3.新开起一个终端输入

# mysql -u root mysql

mysql> delete from user where USER='';

mysql> FLUSH PRIVILEGES;

记得要这句话,否则如果关闭先前的终端,又会出现原来的错误

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: