Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.82 KB

information-schema-user-attributes.md

File metadata and controls

49 lines (40 loc) · 1.82 KB
title summary
USER_ATTRIBUTES
了解 INFORMATION_SCHEMA 表 `USER_ATTRIBUTES`。

USER_ATTRIBUTES

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

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

USER_ATTRIBUTES 表中列的含义如下:

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

示例:

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