首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >mysql重置密码(仅限测试或者开发环境,线上禁用)

mysql重置密码(仅限测试或者开发环境,线上禁用)

原创
作者头像
@锐
发布2025-12-19 15:44:40
发布2025-12-19 15:44:40
50
举报

mysql版本:8.0.44-0ubuntu0.22.04

  • sudo systemctl stop mysql 关闭mysql进程
  • 在配置文件中新增 skip-grant-tables
    • 编辑配置文件 sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    • 在mysqld下新增一行 skip-grant-tables
    • 保存退出 esc + wq
  • 重启mysql sudo systemctl restart mysql
  • 无密码登录 mysql -u root
  • 清除密码
    • update mysql.user set authentication_string= '' where User='root' and Host='localhost'; 更新用户密码为空
    • flush privileges; 刷新权限
    • exit; 退出mysql
  • 重新编辑配置文件,删除或者注释 skip-grant-tables
  • 重启mysql sudo systemctl restart mysql
  • 无密码登录 mysql -u root
  • 设置新密码
    • alter user 'root'@'localhost' identified by '新密码'; 设置新密码
    • flush privileges;
    • exit;

  • 注释: 为何需要两次修改密码,且操作不同
    • skip-grant-tables的限制
      • mysql 不加载权限表
      • 不检查任何用户权限
      • 可以无密码登录
      • 但不能执行需要权限认证的操作
    • update mysql.user set authentication_string= '' where User='root' and Host='localhost'; 操作不涉及密码加密,不更新相关缓存
    • alter user 'root'@'localhost' identified by '新密码';操作会涉及密码加密,skip-grant-tables模式下无法执行

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档