mysql重置密码

来源:互联网 发布:淘宝网冬季女款棉服 编辑:程序博客网 时间:2024/06/01 08:47

修改mysql配置文件/etc/my.cnf,在[mysqld] 下增加一行:

[mysqld]skip-grant-tables

保存并重启mysql

service mysqld restart

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

mysql -uroot -p

选择数据库

use mysql;

修改密码:

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,然后就可以用新的密码登录了。