CentOS修改MySQL忘记root密码

找到MySQL配置文件/etc/my.cnf,找一行加入以下内容跳过表的授权

skip-grant-tables

执行/etc/init.d/mysqld restart或service mysqld restart重启mysql

root用户登录直接MySQL,提示密码直接回车

mysql -uroot -p

有密码提示也忽略,回车即可。

然后执行修改密的命令和刷新纪录。

mysql5.7执行修改密码语句是

update mysql.user set authentication_string=password('新密码') where user='root';

MySQL是5.7以下,则修改密码的语句是

update mysql.user set password=password('新密码') where user='root';
flush privileges;//刷库

接下来去掉配置文件里面刚才添加的参数,再重启mysql就可以了。

此条目发表在服务器分类目录,贴了标签。将固定链接加入收藏夹。

发表回复