MySQL 忘记 root密码 处理方法
原文:互联网老辛 https://blog.51cto.com/xinsz08/1859063
mysql 版本不同,修改密码的方法大同小异,但是有一定的区别:
vim /etc/my.cnf 加上 skip-grant-tables systemctl restart mysqld mysql update mysql.user set authentication_string = password('123456') where user = 'root' ; quit; vim /etc/my.cnf 去掉 skip-grant-tables systemctl restart mysqld
mysql 5.1
1.确认没有人能够连接 MySQL 数据库。
2.修改MySQL的登录设置:
vim /etc/my.cnf
在 [mysqld] 的段中加上一句:
skip-grant-tables
保存并且退出
3.重新启动
systemctl restart mysqld
4.修改 MySQL 的 root 密码
mysql; use mysql; update user set password = password ( '123456' ) where user = 'root' and host = 'localhost'; flush privileges ; quit;
5.7 版本的数据库下的 user 表里面已经没有 password 了
而是将加密后的用户密码存储在 authentication_string 字段下面
update mysql.user set authentication_string = password('123456') where user = 'root' and host = 'localhost';
5.将MySQL的登录设置修改回来
vim /etc/my.cnf
将刚才在 [mysqld] 的段中的 skip-grant-tables 删除
6.重新启动mysqld
systemctl restart mysqld;
7.如果操作功能不完全,登录数据库:
mysql -p alter mysql.user 'root'@'localhost' identified by '123456'; select user,host,create_priv,super_priv,grant_priv,password_last_changed,account_locked from mysql.user; flush privileges; quit;
----------------------------------
互联网老辛
https://blog.51cto.com/xinsz08/1859063
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!