USER_ATTRIBUTES

USER_ATTRIBUTES 表提供了用户的注释和属性。该表的数据根据 mysql.user 系统表生成。

1. USE information_schema;
2. DESC user_attributes;
1. +-----------+--------------+------+------+---------+-------+
2. | Field     | Type         | Null | Key  | Default | Extra |
3. +-----------+--------------+------+------+---------+-------+
4. | USER      | varchar(32)  | NO   |      | NULL    |       |
5. | HOST      | varchar(255) | NO   |      | NULL    |       |
6. | ATTRIBUTE | longtext     | YES  |      | NULL    |       |
7. +-----------+--------------+------+------+---------+-------+
8. 3 rows in set (0.00 sec)

USER_ATTRIBUTES 表中列的含义如下:

  • USER:用户名。
  • HOST:用户可用于连接的主机。百分号(%)表示主机名不受限制。
  • ATTRIBUTE:通过 CREATE USER 或 ALTER USER 语句设置的用户相关的注释和属性。

示例:

1. CREATE USER testuser1 COMMENT 'This user is created only for test';
2. CREATE USER testuser2 ATTRIBUTE '{"email": "user@pingcap.com"}';
3. SELECT * FROM information_schema.user_attributes;
1. +-----------+------+---------------------------------------------------+
2. | USER      | HOST | ATTRIBUTE                                         |
3. +-----------+------+---------------------------------------------------+
4. | root      | %    | NULL                                              |
5. | testuser1 | %    | {"comment": "This user is created only for test"} |
6. | testuser2 | %    | {"email": "user@pingcap.com"}                     |
7. +-----------+------+---------------------------------------------------+
8. 3 rows in set (0.00 sec)