MySQL修改用户的密码主要有两种方法:ALTER USER 和SET PASSWORD
1. alter user
基本使用:
alter user 用户名[@"主机"] identified by "密码";
修改当前登陆用户的密码
alter user user() identified by "密码";
使密码过期:
alter user 用户名[@"主机"] identified by "密码" password expire;
使密码从不过期:
alter user 用户名[@"主机"] identified by "密码" password expire never;
按默认设置过期时间:
alter user 用户名[@"主机"] identified by "密码" password expire default;
指定过期间隔:
alter user 用户名[@"主机"] identified by "密码" password expire interval 90 day;
在MySQL文档里,推荐使用ALTER USER修改用户密码
2. set password
使用默认加密:
set password for 用户名 = "密码";
使用password()函数加密:
set password for 用户名 = password("密码");