Mysql (Linux) 忘记密码,重置密码

1 关闭mysql 服务

systemctl stop mysqld

2 . 修改mysql 配置文件,跳过密码登录

echo skip-grant-tables >> /etc/my.cnf

3 . 开启mysql 服务,并登录mysql (不需要密码)

mysql

4 . 更改mysql系统中user表中登录用户的密码

--使用mysql 数据库
use mysql 
--更新密码
--update user set password=password("要更改的密码") where user="更改的用户名";
--注意版本区别,在新版本中 提示没有这个password 字段,密码字段是authentication_string
--update user set authentication_string=password("要更改的密码") where user="更改的用户名";
update user set authentication_string=password("root") where user="root";
--刷新权限
flush privileges;
```[图片上传中...(dog.jpg-edd842-1533830145621-0)]

# 5 . 还原配置文件,并重启服务并登录

--将刚才修改的 mysql配置文件还原,删除最后一行,vi /etc/my.cnf
skip-grant-tables
--重启mysql 服务
systemctl restart mysqld
--使用新密码登录mysql
mysql -uroot -proot

# 6 . 修改密码完成 ,检查是否能够登录,并创建 库表






![dog.jpg](https://upload-images.jianshu.io/upload_images/13032930-8d86b5217d17b199.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。