From 89a6a2dfb9e96ed29012146fad36d1d05a2a2681 Mon Sep 17 00:00:00 2001 From: qiancai Date: Thu, 27 Oct 2022 23:41:23 +0800 Subject: [PATCH 01/10] Create information-schema-user-attributes.md --- .../information-schema-user-attributes.md | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 information-schema/information-schema-user-attributes.md diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md new file mode 100644 index 0000000000000..b53a0498e1b56 --- /dev/null +++ b/information-schema/information-schema-user-attributes.md @@ -0,0 +1,49 @@ +--- +title: USER_ATTRIBUTES +summary: Learn the `USER_ATTRIBUTES` INFORMATION_SCHEMA table. +--- + +# USER_ATTRIBUTES + +The `USER_PRIVILEGES` table provides information about user comments and user attributes. This information comes from the `mysql.user` system table: + +```sql +USE information_schema; +DESC user_attributes; +``` + +```sql ++-----------+--------------+------+------+---------+-------+ +| 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) +``` + +Fields in the `USER_ATTRIBUTES` table are described as follows: + +* `USER`:The user name. +* `HOST`:The host from which the user can connect to TiDB. If the value of this field is `%`, it means that the user can connect to TiDB from any host. +* `ATTRIBUTE`:The comment and attribute of the user, which are set by the [`CREATE USER`](/sql-statements/sql-statement-create-user.md) or [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) statement. + +The following is an example: + +```sql +CREATE USER testuser1 COMMENT 'This user is created only for test'; +CREATE USER testuser2 ATTRIBUTE '{"email": "user@pingcap.com"}'; +SELECT * FROM user_attributes; +``` + +```sql ++-----------+------+---------------------------------------------------+ +| 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) +``` \ No newline at end of file From a1003a78ebc069ef7972775b3f9636bb6c119887 Mon Sep 17 00:00:00 2001 From: qiancai Date: Fri, 28 Oct 2022 23:22:41 +0800 Subject: [PATCH 02/10] add translations --- TOC.md | 1 + information-schema/information-schema.md | 1 + sql-statements/sql-statement-alter-user.md | 28 ++++++- sql-statements/sql-statement-create-user.md | 28 ++++++- .../sql-statement-show-columns-from.md | 81 ++++++++++--------- 5 files changed, 99 insertions(+), 40 deletions(-) diff --git a/TOC.md b/TOC.md index 9bdab96272683..02151137a3f3d 100644 --- a/TOC.md +++ b/TOC.md @@ -806,6 +806,7 @@ - [`TIKV_REGION_PEERS`](/information-schema/information-schema-tikv-region-peers.md) - [`TIKV_REGION_STATUS`](/information-schema/information-schema-tikv-region-status.md) - [`TIKV_STORE_STATUS`](/information-schema/information-schema-tikv-store-status.md) + - [`USER_ATTRIBUTES`](/information-schema/information-schema-user-attributes.md) - [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) - [`VARIABLES_INFO`](/information-schema/information-schema-variables-info.md) - [`VIEWS`](/information-schema/information-schema-views.md) diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 891ada720d75d..63ecbc99f037d 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -44,6 +44,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi | [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) | Provides information on primary keys, unique indexes and foreign keys. | | `TABLE_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. | | `TRIGGERS` | Not implemented by TiDB. Returns zero rows. | +| [`USER_ATTRIBUTES`](/information-schema/information-schema-user-attributes.md) | Summarizes information about user comments and user attributes. | [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) | Summarizes the privileges associated with the current user. | | [`VARIABLES_INFO`](/information-schema/information-schema-variables-info.md) | Provides information about TiDB system variables. | | [`VIEWS`](/information-schema/information-schema-views.md) | Provides a list of views that the current user has visibility of. Similar to running `SHOW FULL TABLES WHERE table_type = 'VIEW'` | diff --git a/sql-statements/sql-statement-alter-user.md b/sql-statements/sql-statement-alter-user.md index ba1f4071b4847..d29a33d2fae35 100644 --- a/sql-statements/sql-statement-alter-user.md +++ b/sql-statements/sql-statement-alter-user.md @@ -12,7 +12,7 @@ This statement changes an existing user inside the TiDB privilege system. In the ```ebnf+diagram AlterUserStmt ::= - 'ALTER' 'USER' IfExists (UserSpecList RequireClauseOpt ConnectionOptions LockOption | 'USER' '(' ')' 'IDENTIFIED' 'BY' AuthString) + 'ALTER' 'USER' IfExists (UserSpecList RequireClauseOpt ConnectionOptions LockOption AttributeOption | 'USER' '(' ')' 'IDENTIFIED' 'BY' AuthString) UserSpecList ::= UserSpec ( ',' UserSpec )* @@ -27,6 +27,8 @@ AuthOption ::= ( 'IDENTIFIED' ( 'BY' ( AuthString | 'PASSWORD' HashString ) | 'WITH' StringName ( 'BY' AuthString | 'AS' HashString )? ) )? LockOption ::= ( 'ACCOUNT' 'LOCK' | 'ACCOUNT' 'UNLOCK' )? + +AttributeOption ::= ( 'COMMENT' CommentString | 'ATTRIBUTE' AttributeString )? ``` ## Examples @@ -63,6 +65,30 @@ ALTER USER 'newuser' ACCOUNT LOCK; Query OK, 0 rows affected (0.02 sec) ``` +```sql +ALTER USER 'newuser' ATTRIBUTE '{"newAttr": "value", "deprecatedAttr": null}'; +``` + +``` +Query OK, 0 rows affected (0.02 sec) +``` + +```sql +ALTER USER 'newuser' COMMENT 'Here is the comment'; +``` + +``` +Query OK, 0 rows affected (0.02 sec) +``` + +```sql +ALTER USER 'newuser' ATTRIBUTE '{"comment": null}'; +``` + +``` +Query OK, 0 rows affected (0.02 sec) +``` + > **Note:** > > Do not use `ACCOUNT UNLOCK` to unlock a [role](/sql-statements/sql-statement-create-role.md). Otherwise, the unlocked role can be used to log in to TiDB without password. diff --git a/sql-statements/sql-statement-create-user.md b/sql-statements/sql-statement-create-user.md index d77e194be49cd..f2976b6bb95d6 100644 --- a/sql-statements/sql-statement-create-user.md +++ b/sql-statements/sql-statement-create-user.md @@ -12,7 +12,7 @@ This statement creates a new user, specified with a password. In the MySQL privi ```ebnf+diagram CreateUserStmt ::= - 'CREATE' 'USER' IfNotExists UserSpecList RequireClauseOpt ConnectionOptions LockOption + 'CREATE' 'USER' IfNotExists UserSpecList RequireClauseOpt ConnectionOptions LockOption AttributeOption IfNotExists ::= ('IF' 'NOT' 'EXISTS')? @@ -31,6 +31,8 @@ StringName ::= | Identifier LockOption ::= ( 'ACCOUNT' 'LOCK' | 'ACCOUNT' 'UNLOCK' )? + +AttributeOption ::= ( 'COMMENT' CommentString | 'ATTRIBUTE' AttributeString )? ``` ## Examples @@ -73,6 +75,30 @@ CREATE USER 'newuser5'@'%' ACCOUNT LOCK; Query OK, 1 row affected (0.02 sec) ``` +Create a user with a comment. + +{{< copyable "sql" >}} + +```sql +CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test'; +``` + +``` +Query OK, 1 row affected (0.02 sec) +``` + +Create a user with an `email` attribute: + +{{< copyable "sql" >}} + +```sql +CREATE USER 'newuser7'@'%' ATTRIBUTE '{"email": "user@pingcap.com"}'; +``` + +``` +Query OK, 1 row affected (0.02 sec) +``` + ## MySQL compatibility The following `CREATE USER` options are not yet supported by TiDB, and will be parsed but ignored: diff --git a/sql-statements/sql-statement-show-columns-from.md b/sql-statements/sql-statement-show-columns-from.md index f94a90618f9f8..79e15bb6a9f8b 100644 --- a/sql-statements/sql-statement-show-columns-from.md +++ b/sql-statements/sql-statement-show-columns-from.md @@ -111,44 +111,49 @@ mysql> show full columns from v1; 1 row in set (0.00 sec) mysql> show full columns from mysql.user; -+-----------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ -| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | -+-----------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ -| Host | char(64) | utf8mb4_bin | NO | PRI | NULL | | select,insert,update,references | | -| User | char(32) | utf8mb4_bin | NO | PRI | NULL | | select,insert,update,references | | -| authentication_string | text | utf8mb4_bin | YES | | NULL | | select,insert,update,references | | -| Select_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Insert_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Update_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Delete_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Drop_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Process_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Grant_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| References_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Alter_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Show_db_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Super_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_tmp_table_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Lock_tables_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Execute_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_view_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Show_view_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_routine_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Alter_routine_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Index_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_user_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Event_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Trigger_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Create_role_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Drop_role_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Account_locked | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Shutdown_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Reload_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| FILE_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -| Config_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | -+-----------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ -33 rows in set (0.01 sec) ++------------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ +| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | ++------------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ +| Host | char(255) | utf8mb4_bin | NO | PRI | NULL | | select,insert,update,references | | +| User | char(32) | utf8mb4_bin | NO | PRI | NULL | | select,insert,update,references | | +| authentication_string | text | utf8mb4_bin | YES | | NULL | | select,insert,update,references | | +| plugin | char(64) | utf8mb4_bin | YES | | NULL | | select,insert,update,references | | +| Select_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Insert_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Update_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Delete_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Drop_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Process_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Grant_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| References_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Alter_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Show_db_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Super_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_tmp_table_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Lock_tables_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Execute_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_view_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Show_view_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_routine_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Alter_routine_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Index_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_user_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Event_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Repl_slave_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Repl_client_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Trigger_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_role_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Drop_role_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Account_locked | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Shutdown_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Reload_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| FILE_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Config_priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| Create_Tablespace_Priv | enum('N','Y') | utf8mb4_bin | NO | | N | | select,insert,update,references | | +| User_attributes | json | NULL | YES | | NULL | | select,insert,update,references | | ++------------------------+---------------+-------------+------+------+---------+-------+---------------------------------+---------+ +38 rows in set (0.00 sec) ``` ## MySQL compatibility From 4e342e35e3b80d0cc7f85ae91f75c6026affa97f Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Fri, 28 Oct 2022 23:27:05 +0800 Subject: [PATCH 03/10] Update sql-statements/sql-statement-create-user.md --- sql-statements/sql-statement-create-user.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-statements/sql-statement-create-user.md b/sql-statements/sql-statement-create-user.md index f2976b6bb95d6..12cf91abd1c94 100644 --- a/sql-statements/sql-statement-create-user.md +++ b/sql-statements/sql-statement-create-user.md @@ -87,7 +87,7 @@ CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test'; Query OK, 1 row affected (0.02 sec) ``` -Create a user with an `email` attribute: +Create a user with an `email` attribute. {{< copyable "sql" >}} From 0a1651a2712c5714becc21b3177fc39499c5a52a Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 1 Nov 2022 10:29:14 +0800 Subject: [PATCH 04/10] Update information-schema/information-schema-user-attributes.md --- information-schema/information-schema-user-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md index b53a0498e1b56..0157d4efea939 100644 --- a/information-schema/information-schema-user-attributes.md +++ b/information-schema/information-schema-user-attributes.md @@ -5,7 +5,7 @@ summary: Learn the `USER_ATTRIBUTES` INFORMATION_SCHEMA table. # USER_ATTRIBUTES -The `USER_PRIVILEGES` table provides information about user comments and user attributes. This information comes from the `mysql.user` system table: +The `USER_PRIVILEGES` table provides information about user comments and user attributes. This information comes from the `mysql.user` system table. ```sql USE information_schema; From 3f21ae13f8f25d914314e90aec8a43e768ef21fb Mon Sep 17 00:00:00 2001 From: qiancai Date: Tue, 1 Nov 2022 11:56:27 +0800 Subject: [PATCH 05/10] fix punctuations --- information-schema/information-schema-user-attributes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md index b53a0498e1b56..922f5939f3c02 100644 --- a/information-schema/information-schema-user-attributes.md +++ b/information-schema/information-schema-user-attributes.md @@ -25,9 +25,9 @@ DESC user_attributes; Fields in the `USER_ATTRIBUTES` table are described as follows: -* `USER`:The user name. -* `HOST`:The host from which the user can connect to TiDB. If the value of this field is `%`, it means that the user can connect to TiDB from any host. -* `ATTRIBUTE`:The comment and attribute of the user, which are set by the [`CREATE USER`](/sql-statements/sql-statement-create-user.md) or [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) statement. +* `USER`: The user name. +* `HOST`: The host from which the user can connect to TiDB. If the value of this field is `%`, it means that the user can connect to TiDB from any host. +* `ATTRIBUTE`: The comment and attribute of the user, which are set by the [`CREATE USER`](/sql-statements/sql-statement-create-user.md) or [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) statement. The following is an example: From 45622af5670060b0cd3593e01a1686c8f037a0dd Mon Sep 17 00:00:00 2001 From: CbcWestwolf <1004626265@qq.com> Date: Tue, 1 Nov 2022 13:19:58 +0800 Subject: [PATCH 06/10] Update information-schema/information-schema.md Co-authored-by: Aolin --- information-schema/information-schema.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema.md b/information-schema/information-schema.md index 63ecbc99f037d..4bff3e181259c 100644 --- a/information-schema/information-schema.md +++ b/information-schema/information-schema.md @@ -44,7 +44,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi | [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) | Provides information on primary keys, unique indexes and foreign keys. | | `TABLE_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. | | `TRIGGERS` | Not implemented by TiDB. Returns zero rows. | -| [`USER_ATTRIBUTES`](/information-schema/information-schema-user-attributes.md) | Summarizes information about user comments and user attributes. +| [`USER_ATTRIBUTES`](/information-schema/information-schema-user-attributes.md) | Summarizes information about user comments and user attributes. | | [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) | Summarizes the privileges associated with the current user. | | [`VARIABLES_INFO`](/information-schema/information-schema-variables-info.md) | Provides information about TiDB system variables. | | [`VIEWS`](/information-schema/information-schema-views.md) | Provides a list of views that the current user has visibility of. Similar to running `SHOW FULL TABLES WHERE table_type = 'VIEW'` | From cc0fcd337f2c5286382a47ddf69073845dafab56 Mon Sep 17 00:00:00 2001 From: CbcWestwolf <1004626265@qq.com> Date: Wed, 2 Nov 2022 15:53:57 +0800 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Aolin --- .../information-schema-user-attributes.md | 6 ++-- sql-statements/sql-statement-alter-user.md | 36 +++++++++++++++---- sql-statements/sql-statement-create-user.md | 4 --- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md index 0157d4efea939..b8a102f1ed171 100644 --- a/information-schema/information-schema-user-attributes.md +++ b/information-schema/information-schema-user-attributes.md @@ -25,9 +25,9 @@ DESC user_attributes; Fields in the `USER_ATTRIBUTES` table are described as follows: -* `USER`:The user name. -* `HOST`:The host from which the user can connect to TiDB. If the value of this field is `%`, it means that the user can connect to TiDB from any host. -* `ATTRIBUTE`:The comment and attribute of the user, which are set by the [`CREATE USER`](/sql-statements/sql-statement-create-user.md) or [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) statement. +* `USER`: The user name. +* `HOST`: The host from which the user can connect to TiDB. If the value of this field is `%`, it means that the user can connect to TiDB from any host. +* `ATTRIBUTE`: The comment and attribute of the user, which are set by the [`CREATE USER`](/sql-statements/sql-statement-create-user.md) or [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) statement. The following is an example: diff --git a/sql-statements/sql-statement-alter-user.md b/sql-statements/sql-statement-alter-user.md index d29a33d2fae35..8b29341f533a2 100644 --- a/sql-statements/sql-statement-alter-user.md +++ b/sql-statements/sql-statement-alter-user.md @@ -65,28 +65,52 @@ ALTER USER 'newuser' ACCOUNT LOCK; Query OK, 0 rows affected (0.02 sec) ``` +Modify the attributes of `newuser`: + ```sql ALTER USER 'newuser' ATTRIBUTE '{"newAttr": "value", "deprecatedAttr": null}'; +SELECT * FROM information_schema.user_attributes; ``` +```sql ++-----------+------+--------------------------+ +| USER | HOST | ATTRIBUTE | ++-----------+------+--------------------------+ +| newuser | % | {"newAttr": "value"} | ++-----------+------+--------------------------+ +1 rows in set (0.00 sec) ``` -Query OK, 0 rows affected (0.02 sec) -``` + +Modify the comment of `newuser` using `ALTER USER ... COMMENT`: ```sql ALTER USER 'newuser' COMMENT 'Here is the comment'; +SELECT * FROM information_schema.user_attributes; ``` +```sql ++-----------+------+--------------------------------------------------------+ +| USER | HOST | ATTRIBUTE | ++-----------+------+--------------------------------------------------------+ +| newuser | % | {"comment": "Here is the comment", "newAttr": "value"} | ++-----------+------+--------------------------------------------------------+ +1 rows in set (0.00 sec) ``` -Query OK, 0 rows affected (0.02 sec) -``` + +Modify the comment of `newuser` using `ALTER USER ... ATTRIBUTE`: ```sql ALTER USER 'newuser' ATTRIBUTE '{"comment": null}'; +SELECT * FROM information_schema.user_attributes; ``` -``` -Query OK, 0 rows affected (0.02 sec) +```sql ++-----------+------+---------------------------+ +| USER | HOST | ATTRIBUTE | ++-----------+------+---------------------------+ +| newuser | % | {"newAttr": "value"} | ++-----------+------+---------------------------+ +1 rows in set (0.00 sec) ``` > **Note:** diff --git a/sql-statements/sql-statement-create-user.md b/sql-statements/sql-statement-create-user.md index 12cf91abd1c94..0d443693c84ec 100644 --- a/sql-statements/sql-statement-create-user.md +++ b/sql-statements/sql-statement-create-user.md @@ -77,8 +77,6 @@ Query OK, 1 row affected (0.02 sec) Create a user with a comment. -{{< copyable "sql" >}} - ```sql CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test'; ``` @@ -89,8 +87,6 @@ Query OK, 1 row affected (0.02 sec) Create a user with an `email` attribute. -{{< copyable "sql" >}} - ```sql CREATE USER 'newuser7'@'%' ATTRIBUTE '{"email": "user@pingcap.com"}'; ``` From a91a685a82ba22c5e93d5821bfbe8b9e29fb67ea Mon Sep 17 00:00:00 2001 From: qiancai Date: Sun, 6 Nov 2022 11:22:01 +0800 Subject: [PATCH 08/10] align with the Chinese changes --- sql-statements/sql-statement-alter-user.md | 6 +----- sql-statements/sql-statement-create-user.md | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sql-statements/sql-statement-alter-user.md b/sql-statements/sql-statement-alter-user.md index 8b29341f533a2..3e5bfa7b506f1 100644 --- a/sql-statements/sql-statement-alter-user.md +++ b/sql-statements/sql-statement-alter-user.md @@ -97,7 +97,7 @@ SELECT * FROM information_schema.user_attributes; 1 rows in set (0.00 sec) ``` -Modify the comment of `newuser` using `ALTER USER ... ATTRIBUTE`: +Remove the comment of `newuser` using `ALTER USER ... ATTRIBUTE`: ```sql ALTER USER 'newuser' ATTRIBUTE '{"comment": null}'; @@ -117,10 +117,6 @@ SELECT * FROM information_schema.user_attributes; > > Do not use `ACCOUNT UNLOCK` to unlock a [role](/sql-statements/sql-statement-create-role.md). Otherwise, the unlocked role can be used to log in to TiDB without password. -## MySQL compatibility - -* In MySQL this statement is used to change attributes such as to expire a password. This functionality is not yet supported by TiDB. - ## See also diff --git a/sql-statements/sql-statement-create-user.md b/sql-statements/sql-statement-create-user.md index 0d443693c84ec..35a3629c92960 100644 --- a/sql-statements/sql-statement-create-user.md +++ b/sql-statements/sql-statement-create-user.md @@ -79,20 +79,32 @@ Create a user with a comment. ```sql CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test'; +SELECT * FROM information_schema.user_attributes; ``` ``` -Query OK, 1 row affected (0.02 sec) ++-----------+------+---------------------------------------------------+ +| USER | HOST | ATTRIBUTE | ++-----------+------+---------------------------------------------------+ +| newuser6 | % | {"comment": "This user is created only for test"} | ++-----------+------+---------------------------------------------------+ +1 rows in set (0.00 sec) ``` Create a user with an `email` attribute. ```sql CREATE USER 'newuser7'@'%' ATTRIBUTE '{"email": "user@pingcap.com"}'; +SELECT * FROM information_schema.user_attributes; ``` -``` -Query OK, 1 row affected (0.02 sec) +```sql ++-----------+------+---------------------------------------------------+ +| USER | HOST | ATTRIBUTE | ++-----------+------+---------------------------------------------------+ +| newuser7 | % | {"email": "user@pingcap.com"} | ++-----------+------+---------------------------------------------------+ +1 rows in set (0.00 sec) ``` ## MySQL compatibility From 3032396a49efe9c7b56b6bbf72665bfaf024d37d Mon Sep 17 00:00:00 2001 From: CbcWestwolf <1004626265@qq.com> Date: Mon, 7 Nov 2022 11:19:52 +0800 Subject: [PATCH 09/10] Update information-schema/information-schema-user-attributes.md Co-authored-by: Aolin --- information-schema/information-schema-user-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md index b8a102f1ed171..8d34e3a7ed78e 100644 --- a/information-schema/information-schema-user-attributes.md +++ b/information-schema/information-schema-user-attributes.md @@ -34,7 +34,7 @@ The following is an example: ```sql CREATE USER testuser1 COMMENT 'This user is created only for test'; CREATE USER testuser2 ATTRIBUTE '{"email": "user@pingcap.com"}'; -SELECT * FROM user_attributes; +SELECT * FROM information_schema.user_attributes ``` ```sql From 826c0cb3deec0be874b06cca86a93ba1bc2f28ee Mon Sep 17 00:00:00 2001 From: Aolin Date: Mon, 7 Nov 2022 11:53:54 +0800 Subject: [PATCH 10/10] Apply suggestions from code review --- information-schema/information-schema-user-attributes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/information-schema/information-schema-user-attributes.md b/information-schema/information-schema-user-attributes.md index 8d34e3a7ed78e..c2d31494a3819 100644 --- a/information-schema/information-schema-user-attributes.md +++ b/information-schema/information-schema-user-attributes.md @@ -34,7 +34,7 @@ The following is an example: ```sql 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 +SELECT * FROM information_schema.user_attributes; ``` ```sql