mysql忘记密码修改密码操作 window&linux - 日理万妓 2022-02-23 15:20 221阅读 0赞 window系统 * 关闭 MySQL服务 在mysql安装的bin目录中以管理者的身份进行关闭 执行 net stop mysql * 然后输入执行 mysqld --skip-grant-tables 让 mysqld 启动时不对密码进行验证 * 再开一个DOS窗口,转到mysq/bin目录下。 * 输入mysql回车,如果成功,则登录成功。 * 切换到权限数据库 use mysql; * 进行修改密码 update user set authentication\_string = password('root'), password\_expired = 'N', password\_last\_changed = now() where user = 'root'; * 在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication\_string * 刷新权限(必须的步骤)>flush privileges; * exit; 退出mysql * 然后关闭执行mysqld --skip-grant-tables的doc窗口 在用mysql -u账号 -p密码方式进行登陆即可 linux 1. 修改 /etc/my.cnf,在 \[mysqld\] 小节下添加一行:skip-grant-tables=1 2. 这一行配置让 mysqld 启动时不对密码进行验证 3. 重启 mysqld 服务:systemctl restart mysqld 4. 使用 root 用户登录到 mysql:mysql -u root 5. 切换到mysql数据库 use mysql; ,更新 user 表: 6. update user set authentication\_string = password('root'), password\_expired = 'N', password\_last\_changed = now() where user = 'root'; 7. 退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1 的内容 8. 重启 mysqld 服务,再用新密码登录即可
还没有评论,来说两句吧...