本人环境为MySQL 5.7 + CentOS 6.3。
1. 编辑MySQL配置文件/etc/my.cnf
- 找到[mysqld],在下面添加一行skip-grant-tables
2. 重启MySQL
- service mysqld restart
3. root用户登录MySQL,提示密码直接回车
- mysql -uroot -p
4. 修改root密码,并刷新权限
- update mysql.user set authentication_string=password('新密码') where user='root' and host='localhost';
- flush privileges;
5. 退出MySQL,并编辑MySQL配置文件/etc/my.cnf

6. 重启MySQL
- service mysqld restart

注意:如果MySQL是5.5,则修改密码的语句是update mysql.user set password=password('123456') where user='root' and host='localhost';
本文介绍了一种在MySQL5.7环境下临时禁用权限验证来重置root用户密码的方法,并提供了适用于不同版本的具体操作步骤。
283

被折叠的 条评论
为什么被折叠?



