Skip to content

MySQL8修改密码

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

1、如果不为空

mysql
use mysql;

将字段置为空

mysql
update user set authentication_string='' where user='root';

修改密码为123456

mysql
ALTER user 'root'@'localhost' IDENTIFIED BY '123456';

2、如果为空,直接修改

mysql
ALTER user 'root'@'localhost' IDENTIFIED BY '123456';

如果出现类似如下错误

mysql
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;

需要刷新权限

mysql
flush privileges;

然后再执行

mysql
ALTER user 'root'@'localhost' IDENTIFIED BY '123456';

最近更新:10/11/2024, 4:53:28 AM

原文链接:MySQL8修改密码

|下一篇:MySQL:ERROR 1410 (42000)