MySQL 8.0重置密码

MySQL 8.0修改账号密码的方式和前面的版本不一样,按照网上常见的方法执行是不行的,因此记录一下。

  1. 设置跳过密码登录:打开 /etc/my.cnf,并在 [mysqld] 下面增加 skip-grant-tables
  2. 登录:mysql -u root -p (直接回车)
  3. 切换到mysql d: use mysql
  4. 执行:update user set authentication_string = '' where user = 'root';
  5. 刷新权限:flush privileges;
  6. 重置密码:alter user 'root'@'%' identified by '你的密码';
  7. 刷新权限:flush privileges;
  8. 退出 mysql,并且把 /etc/my.cnf 的 skip-grant-tables 去掉

你可能感兴趣的:(MySQL 8.0重置密码)