CentOS7修改MySQL8的root账户密码

MySQL5.7.9后废弃了password字段和password()函数,authentication_string字段表示用户密码,authentication_string字段只能是mysql加密后的41位字符串密码。修改密码的方式较之前发生了改变,可按如下操作修改:

修改前先检查密码是否为空

  • 密码不为空
mysql -u root -p  //登录mysql
use mysql;
update user set authentication_string='' where user='root';  //置空root账号密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'rootpassword';  //修改密码为 rootpassword

在这里插入图片描述
CentOS7修改MySQL8的root账户密码_第1张图片

  • 密码为空
    直接修改密码
ALTER user 'root'@'localhost' IDENTIFIED BY 'rootpassword';

如何出现如下错误:

ERROR 1290 (HY000):The MYSQL server is running with the --skip-grant-tables option so it cannot execute this statement

需要执行:

GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
flush privileges;

最后再修改密码:

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

你可能感兴趣的:(笔记,CentOS,mysql,数据库,database)