MySql 8.0 忘记root密码

/

MySql 从8.0开始,修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空:

1、如果不为空,则先置空

  1. USE mysql;
  2. UPDATE user SET authentication_string='' WHERE user='root';
  3. ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

2、如果为空,直接修改

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

如果出现如下错误:
ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement

  1. mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;

也可以先执行,再修改

  1. FLUSH PRIVILEGES;

然后再执行

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

转载请注明作者和出处,并添加本页链接。
原文链接: //www.wwtou.com/W3cv7Kl.html