mysql5.6 修改密码
目录
- 前言
- 修改密码的方法
- 改表
- SET PASSWORD
- 修改当前登录用户的密码
- 修改其他人的密码
- ALTER USER
- 修改当前登录用户的密码
- 修改其他人的密码
- 查看加密后的密码
- 参考
前言
- CentOS
- 5.6.51 MySQL Community Server (GPL)
- 查看MySQL的版本
修改密码的方法
- 改表
- ALTER USER
- SET PASSWORD
改表
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row affected (0.00 sec)
mysql> UPDATE `user` SET `password`=PASSWORD('MyNewPass4!') WHERE `user`='root' AND `host`='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)
SET PASSWORD
修改当前登录用户的密码
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> set password=password('MyNewPass4!');
Query OK, 0 rows affected (0.00 sec)
- user() 方法将返回当前用户信息
修改其他人的密码
mysql> set password for 'test'@'localhost' = password('MyNewPass4!');
ALTER USER
修改当前登录用户的密码
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!';
Query OK, 0 rows affected (0.00 sec)
修改其他人的密码
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!';
密码立即过期:
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!' password expire;
密码永不过期:
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!' password expire never;
密码按默认时间过期:
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!' password expire default;
密码90天后过期:
mysql> alter user 'test'@'localhost' identified by 'MyNewPass4!' password expire interval 90 day;
查看加密后的密码
mysql> select Host,User,Password from user;
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *3A39392171B03872AB76C33513E6534B4BE36F38 |
| 5kqzr | root | |
| 127.0.0.1 | root | *3A39392171B03872AB76C33513E6534B4BE36F38 |
| ::1 | root | *3A39392171B03872AB76C33513E6534B4BE36F38 |
| localhost | | |
| 5kqzr | | |
| % | root | *3A39392171B03872AB76C33513E6534B4BE36F38 |
+-----------+------+-------------------------------------------+
7 rows in set (0.00 sec)
参考
https://blog.csdn.net/feritylamb/article/details/124872763