mysql的用户管理

时间:2021-10-11
本文章向大家介绍mysql的用户管理,主要包括mysql的用户管理使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.Environment
mysql 8.0.21

2.Symptoms
1)服务器查看用户状态
root@mysqldb 16:13: [(none)]> select host,user,password_expired,password_last_changed,password_lifetime,account_locked,Password_reuse_history,Password_reuse_time,Password_require_current from mysql.user;
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
| host | user | password_expired | password_last_changed | password_lifetime | account_locked | Password_reuse_history | Password_reuse_time | Password_require_current |
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
| xx.xxx.5.11 | dbamonitor | N | 2021-07-13 15:51:03 | NULL | N | NULL | NULL | NULL |
| xx.xxx.5.12 | dbamonitor | N | 2021-07-13 15:51:21 | NULL | N | NULL | NULL | NULL |
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
11 rows in set (0.00 sec)


2)客户端使用该用户可以登录,执行sql时提示需要重置密码。
[root@host ~]# mysql -udbamonitor -pXXXXXX -hXX.XXX.2.106 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1370100
Server version: 8.0.21

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql>

3.Changes

4.Cause
虽然从mysql.user中password_lifetime的标记为null,显示用户密码没有过期,没有被锁,但是查看确实是提示需要重置密码;
后来发现当password_lifetime的标记为null时,使用默认有效期,为default_password_lifetime参数控制为90
root@mysqldb 16:22: [(none)]> show variables like '%default_password_lifetime%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| default_password_lifetime | 90 |
+---------------------------+-------+

5.Solution
设置为永不过期
alter user dbamonitor@'xx.xxx.5.11' identified by 'XXXXX' password expire never ;

6.再次测试,客户端就可以正常登陆查询了。
root@mysqldb 16:26: [(none)]> select host,user,password_expired,password_last_changed,password_lifetime,account_locked,Password_reuse_history,Password_reuse_time,Password_require_current from mysql.user;
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
| host | user | password_expired | password_last_changed | password_lifetime | account_locked | Password_reuse_history | Password_reuse_time | Password_require_current |
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
| xx.xxx.5.11 | dbamonitor | N | 2021-10-11 16:26:18 | 0 | N | NULL | NULL | NULL |
| xx.xxx.5.12 | dbamonitor | N | 2021-10-11 16:24:43 | 0 | N | NULL | NULL | NULL |
+---------------+------------------+------------------+-----------------------+-------------------+----------------+------------------------+---------------------+--------------------------+
11 rows in set (0.00 sec)

参考:
https://blog.csdn.net/weixin_34952098/article/details/114341002

原文地址:https://www.cnblogs.com/annez/p/15394096.html