Documentation Home
MySQL Information Schema
Related Documentation Download this Excerpt
PDF (US Ltr) - 333.6Kb
PDF (A4) - 338.0Kb
HTML Download (TGZ) - 59.9Kb
HTML Download (Zip) - 122.0Kb


MySQL Information Schema  /  The INFORMATION_SCHEMA USER_ATTRIBUTES Table

Chapter 41 The INFORMATION_SCHEMA USER_ATTRIBUTES Table

The USER_ATTRIBUTES table provides information about user comments and user attributes. It takes its values from the mysql.user system table.

The USER_ATTRIBUTES table has the following columns:

  • USER

    The user name portion of the account name to which the comment, attribute, or both belong.

  • HOST

    The host name portion of the account name.

  • ATTRIBUTE

    The user comment, user attribute, or both belonging to the user specified by the user and host shown in the previous two columns, in JSON object notation. Attributes are shown exactly as set using CREATE USER ... ATTRIBUTE ... or ALTER USER ... ATTRIBUTE ...; the user comment is shown as a key-value pair having comment as the key.

    For example, the statement CREATE USER 'bill'@'localhost' COMMENT 'A comment' ATTRIBUTE '{"foo": "bar", "bazz": "fazz"}' adds the following row to the USER_ATTRIBUTES table:

    +------+-----------+--------------------------------------------------------+
    | USER | HOST      | ATTRIBUTE                                              |
    +------+-----------+--------------------------------------------------------+
    | bill | localhost | {"foo": "bar", "bazz": "fazz", "comment": "A comment"} |
    +------+-----------+--------------------------------------------------------+

Notes

  • USER_ATTRIBUTES is a nonstandard INFORMATION_SCHEMA table.

  • To obtain only the user comment for a given user as an unquoted string, you can employ a query such as this one:

    mysql> SELECT ATTRIBUTE->>"$.comment" AS Comment
        ->     FROM INFORMATION_SCHEMA.USER_ATTRIBUTES
        ->     WHERE USER='bill' AND HOST='localhost';
    +-----------+
    | Comment   |
    +-----------+
    | A comment |
    +-----------+

    Similarly, you can obtain the unquoted value for a given user attribute using its key.

  • The USER_ATTRIBUTES table was added in MySQL 8.0.21.

For more information, see CREATE USER Statement.