MySQL使用ALTER USER修改密码
本文将介绍在 MySQL 中怎样使用 alter user 修改用户密码。
MySQL修改用户的密码有两种方法:
ALTER USER
下面的语句在 mysql 5.7 版本中执行成功。实例如下:
(1)使用明文的方式修改 test 用户的密码为 123456。如下:
mysql> alter user test identified by '123456';
Query OK, 0 rows affected(2)修改当前登录用户的密码,其中:user() 方法将返回当前用户信息。实例如下:
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> alter user user() identified by 'aaaaaa';
Query OK, 0 rows affected (0.00 sec)(3)使密码过期
mysql> alter user test identified by '123456' password expire;
Query OK, 0 rows affecte(4)使密码从不过期
mysql> alter user test identified by '123456' password expire never;
Query OK, 0 rows affected(5)按默认设置过期时间
mysql> alter user test identified by '123456' password expire default;
Query OK, 0 rows affected(6)指定密码的过期间隔,如下:
mysql> alter user test identified by '123456' password expire interval 90 day;
Query OK, 0 rows affected在 MySQL 文档里,推荐使用 ALTER USER 修改用户密码。ALTER USER 官网参考手册:https://dev.mysql.com/doc/refman/5.7/en/alter-user.html
SET PASSWORD
使用 SET PASSWORD 的密码有两种:
(1)使用默认加密
mysql> set password for test='123456';
ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number错误“ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number”(密码散列应该是一个41位的十六进制数字)意思是不能输入明文,可以使用 password('') 来生成密码。
(2)使用 PASSWORD() 函数加密
mysql> set password for test=password('123abc');
Query OK, 0 rows affected注意:使用 PASSWORD('auth_string') 的方式已经被废弃,在以后的版本会把它移除,所以不建议使用它来修改密码。
真理惟一可靠的标准就是永远自相符合。 —— 欧文
说说我的看法 -
还可使用 Gitee / GitHub 账号一键登录,与大家分享你的观点
立即登录
全部评论()
没有评论
- MySQL 早期实现的 UTF8 并非完整的 UTF-8 标准
- MySQL 支持的数字数据类型,看看你了解多少
- MySQL 存储过程的 DECLARE 语句
- MySQL 的 BEGIN ... END 复合语句
- MySQL DECLARE ... HANDLER 语句
- MySQL 如何备份数据表
- MySQL 创建函数提示“1418 - This function has none of DETERMNISTIC, NO SOL,or READS SOL DATA in its declaration and binary logging is enabled ”错误
- CentOS7 开启 MySQL 远程访问
- mysqladmin 命令详解
- MySQL 免安装版本启动和停止