MySQL 忘记密码

  1. 关闭正在运行的mysql服务
  2. 以安全模式启动mysql
mysqld --shared-memory --skip-grant-tables --console
  1. 使用另一个命令行连接mysql数据库。无需输入密码,直接回车跳过
mysql -uroot -p
  1. 修改权限
use mysql
update user set authentication_string='' where user='root'
flush privileges
alter user 'root'@'localhost' identified by '你想要修改的密码'
  1. 退出后正常重启mysql服务

mysql密码有一定格式,可能会影响第三方终端连接,此时请采用ALTER USER'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码'设置密码

posted @ 2022-11-03 10:24  neumy  阅读(16)  评论(0编辑  收藏  举报