-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add description about user ATTRIBUTE (#11084)
- Loading branch information
Showing
6 changed files
with
180 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]"}'; | ||
SELECT * FROM information_schema.user_attributes; | ||
``` | ||
|
||
```sql | ||
+-----------+------+---------------------------------------------------+ | ||
| USER | HOST | ATTRIBUTE | | ||
+-----------+------+---------------------------------------------------+ | ||
| root | % | NULL | | ||
| testuser1 | % | {"comment": "This user is created only for test"} | | ||
| testuser2 | % | {"email": "[email protected]"} | | ||
+-----------+------+---------------------------------------------------+ | ||
3 rows in set (0.00 sec) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,38 @@ CREATE USER 'newuser5'@'%' ACCOUNT LOCK; | |
Query OK, 1 row affected (0.02 sec) | ||
``` | ||
|
||
Create a user with a comment. | ||
|
||
```sql | ||
CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test'; | ||
SELECT * FROM information_schema.user_attributes; | ||
``` | ||
|
||
``` | ||
+-----------+------+---------------------------------------------------+ | ||
| 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": "[email protected]"}'; | ||
SELECT * FROM information_schema.user_attributes; | ||
``` | ||
|
||
```sql | ||
+-----------+------+---------------------------------------------------+ | ||
| USER | HOST | ATTRIBUTE | | ||
+-----------+------+---------------------------------------------------+ | ||
| newuser7 | % | {"email": "[email protected]"} | | ||
+-----------+------+---------------------------------------------------+ | ||
1 rows in set (0.00 sec) | ||
``` | ||
|
||
## MySQL compatibility | ||
|
||
The following `CREATE USER` options are not yet supported by TiDB, and will be parsed but ignored: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters