Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description about user ATTRIBUTE #11716

Merged
merged 19 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,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)
Expand Down
51 changes: 51 additions & 0 deletions information-schema/information-schema-user-attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: USER_ATTRIBUTES
summary: 了解 INFORMATION_SCHEMA 表 `USER_ATTRIBUTES`。
---

# USER_ATTRIBUTES

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

{{< copyable "sql" >}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{< copyable "sql" >}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copy syntax is no longer needed for the current docs website. Please remove it from this doc.

```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)
```

CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
{{< copyable "sql" >}}

```sql
CREATE USER testuser1 COMMENT 'This user is created only for test';
CREATE USER testuser2 ATTRIBUTE '{"email": "[email protected]"}';
SELECT * FROM user_attributes;
CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
```

```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)
```

Oreoxmt marked this conversation as resolved.
Show resolved Hide resolved
`USER_ATTRIBUTES` 表中列的含义如下:

* `USER`:用户名。
* `HOST`:用户的主机名。
* `ATTRIBUTE`:用户注释和属性。
CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions information-schema/information-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Information Schema 提供了一种查看系统元数据的 ANSI 标准方法。
| [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md) | 提供有关主键、唯一索引和外键的信息。 |
| `TABLE_PRIVILEGES` | TiDB 未实现,返回零行。 |
| `TRIGGERS` | TiDB 未实现,返回零行。 |
| [`USER_ATTRIBUTES`](/information-schema/information-schema-user-attributes.md) | 汇总与当前用户相关的注释和属性。 |
CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
| [`USER_PRIVILEGES`](/information-schema/information-schema-user-privileges.md) | 汇总与当前用户相关的权限。 |
| [`VARIABLES_INFO`](/information-schema/information-schema-variables-info.md) | 提供 TiDB 系统变量的信息。 |
| [`VIEWS`](/information-schema/information-schema-views.md) | 提供当前用户可见的视图列表。类似于 `SHOW FULL TABLES WHERE table_type = 'VIEW'`。 |
Expand Down
14 changes: 13 additions & 1 deletion sql-statements/sql-statement-alter-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aliases: ['/docs-cn/dev/sql-statements/sql-statement-alter-user/','/docs-cn/dev/

```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 )*
Expand All @@ -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 )?
```

## 示例
Expand Down Expand Up @@ -91,6 +93,16 @@ ALTER USER 'newuser' ACCOUNT LOCK;
Query OK, 0 rows affected (0.02 sec)
```

{{< copyable "sql" >}}

CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
```sql
ALTER USER 'newuser' ATTRIBUTE '{"newAttr": "value", "deprecatedAttr": null}';
```

```
Query OK, 0 rows affected (0.02 sec)
```

> **注意:**
qiancai marked this conversation as resolved.
Show resolved Hide resolved
Oreoxmt marked this conversation as resolved.
Show resolved Hide resolved
>
> 不要使用 `ACCOUNT UNLOCK` 解锁一个[角色 (Role)](/sql-statements/sql-statement-create-role.md),否则通过被解锁的角色可以免密码登入 TiDB。
Expand Down
28 changes: 27 additions & 1 deletion sql-statements/sql-statement-create-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ aliases: ['/docs-cn/dev/sql-statements/sql-statement-create-user/','/docs-cn/dev

```ebnf+diagram
CreateUserStmt ::=
'CREATE' 'USER' IfNotExists UserSpecList RequireClauseOpt ConnectionOptions LockOption
'CREATE' 'USER' IfNotExists UserSpecList RequireClauseOpt ConnectionOptions LockOption AttributeOption

IfNotExists ::=
('IF' 'NOT' 'EXISTS')?
Expand All @@ -31,6 +31,8 @@ StringName ::=
| Identifier

LockOption ::= ( 'ACCOUNT' 'LOCK' | 'ACCOUNT' 'UNLOCK' )?

AttributeOption ::= ( 'COMMENT' CommentString | 'ATTRIBUTE' AttributeString )?
```

## 示例
Expand Down Expand Up @@ -95,6 +97,30 @@ CREATE USER 'newuser5'@'%' ACCOUNT LOCK;
Query OK, 1 row affected (0.02 sec)
```

创建一个带注释的用户。

{{< copyable "sql" >}}

CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
```sql
CREATE USER 'newuser6'@'%' COMMENT 'This user is created only for test';
```

```
Query OK, 1 row affected (0.02 sec)
```

创建一个具有邮箱 (`email`) 属性的用户。

{{< copyable "sql" >}}

CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
```sql
CREATE USER 'newuser7'@'%' ATTRIBUTE '{"email": "[email protected]"}';
```

```
Query OK, 1 row affected (0.02 sec)
```

## MySQL 兼容性

* TiDB 不支持 `WITH MAX_QUERIES_PER_HOUR`、`WITH MAX_UPDATES_PER_HOUR`、`WITH MAX_USER_CONNECTIONS` 等 `CREATE` 选项。
Expand Down
81 changes: 43 additions & 38 deletions sql-statements/sql-statement-show-columns-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,44 +165,49 @@ 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 兼容性
Expand Down