0
0

MySQL8修改密码

2024-01-28
2024-10-11
文章摘要
|

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

1、如果不为空

use mysql; 

将字段置为空

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

修改密码为123456

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

2、如果为空,直接修改

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

如果出现类似如下错误

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;

需要刷新权限

flush privileges;

然后再执行

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

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!