1. 说明

在升级到MySQL 8.0之后我们会发现,有些修改密码的方式在MySQL 8.0中不能继续使用了,下面列出了两个版本的MySQL中修改密码的方式的对比

  1. MySQL 5.7中修改密码的方式
a. alter user方式
   mysql> alter user user() identified by '1q2w3e4r1!';     #这种方式只能修改当前登录用户的方式
   mysql> alter user 'root'@'localhost' identified by '1q2w3e4r1!';   #这种方式可以修改任何用户的密码
b. grant ** identified by方式
   mysql> grant all on *.* to 'root'@'localhost' identified by '1q2w3e4r1!';
c. update命令方式
   mysql> update mysql.user set authentication_string=password('1q2w3e4r1!') where user='root';
d. set password的方式
   mysql>set password for 'root'@'localhost'=password('Abc@12345678');
  1. MySQL 8.0中修改密码的方式
a. alter user方式
   mysql> alter user user() identified by '1q2w3e4r1!';     #这种方式只能修改当前登录用户的方式
   mysql> alter user 'root'@'localhost' identified by '1q2w3e4r1!';   #这种方式可以修改任何用户的密码
b. set password方式
   mysql>set password for 'root'@'localhost'='Abc@12345678';
  1. 注意事项

MySQL 8.0中已经不支持通过grant和update的方式进行密码修改