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)
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)
mysql> set password for 'test'@'localhost' = password('MyNewPass4!');
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