mysql重置root密码(忘记密码)

  1. 关闭权限验证
  • 方法一:
    执行mysqld_safe --skip-grant-tables &
    如果此时不想被远程连接:mysqld_safe --skip-grant-tables --skip-networking &
  • 方法二:
    .用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf
    在[mysqld]下添加skip-grant-tables,然后保存并退出
  1. 重启mysql
  • 5.7之前
    执行service mysqld restart
  • 5.7之后(包括5.7)
    执行systemctl restart mysqld
  1. 进入mysql
    执行mysql
  2. 更改密码:
    执行update mysql.user set authentication_string=password('你要设的新密码') where user='root';

特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了而是将加密后的用户密码存储于authentication_string字段

  1. 刷新退出
    flush privileges;
    quit

  2. 重启
    重新执行第二步

猜你喜欢

转载自blog.csdn.net/lfagon/article/details/85232195
今日推荐