Mysql 忘记root密码的完美解决方法
一、更改my.cnf配置文件[*] 用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnfhttps://files.iyunv.net/file_images/article/201612/201612230849371.pnghttps://files.iyunv.net/file_images/article/201612/201612230849372.png
2.在下添加skip-grant-tables,然后保存并退出
3.重启mysql服务:service mysqld restart
二、更改root用户名
[*] 重启以后,执行mysql命令进入mysql命令行
https://files.iyunv.net/file_images/article/201612/201612230849373.png
2.修改root用户密码
123MySQL> UPDATE mysql.user SET Password=PASSWORD('新密码') where USER='root'; MySQL> flush privileges;MySQL> exit如果是mysql5.7的就用update mysql.user set authentication_string=password('新密码') where user='用户'; 原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string
3.把/etc/my.cnf中的skip-grant-tables注释掉,然后重启mysql,即:service mysqld restart
好了,下面就可以用root新的密码登录了!
页:
[1]