您的位置:首页 > 数据库 > MySQL

mysql 忘记密码处理方法

2018-03-08 09:48 344 查看
修改mysql配置文件/etc/my.cnf,在[mysqld]下增加一行:(作用是可以无密码登录)

[mysqld]

skip-grant-tables


保存并重启mysql

service mysqld restart


登录mysql,无密码,直接回车

mysql -uroot-p


选择数据库

usemysql;


修改密码

update user set password=password('root') where user='root';


5.7版本使用:

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


然后执行:

flush privileges;


退出,再次修改配置文件/etc/my.cnf,把刚才增加的 skip-grant-tables删掉。

保存并再次重启mysql,然后就可以用新的密码登录了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql