Skip to content

Commit da9bd9a

Browse files
authored
update several document related to privilege sql statement (#2828) (#2903)
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
1 parent bd5dc3f commit da9bd9a

File tree

6 files changed

+41
-12
lines changed

6 files changed

+41
-12
lines changed

sql-statements/sql-statement-create-user.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,42 @@ This statement creates a new user, specified with a password. In the MySQL privi
3737

3838
## Examples
3939

40+
Create a user with the `newuserpassword` password.
41+
4042
```sql
4143
mysql> CREATE USER 'newuser' IDENTIFIED BY 'newuserpassword';
4244
Query OK, 1 row affected (0.04 sec)
45+
```
4346

47+
Create a user who can only log in to `192.168.1.1`.
48+
49+
```sql
4450
mysql> CREATE USER 'newuser2'@'192.168.1.1' IDENTIFIED BY 'newuserpassword';
4551
Query OK, 1 row affected (0.02 sec)
4652
```
4753

54+
Create a user who is enforced to log in using TLS connection.
55+
56+
```sql
57+
CREATE USER 'newuser3'@'%' REQUIRE SSL IDENTIFIED BY 'newuserpassword';
58+
Query OK, 1 row affected (0.02 sec)
59+
```
60+
61+
Create a user who is required to use X.509 certificate at login.
62+
63+
```sql
64+
CREATE USER 'newuser4'@'%' REQUIRE ISSUER '/C=US/ST=California/L=San Francisco/O=PingCAP' IDENTIFIED BY 'newuserpassword';
65+
Query OK, 1 row affected (0.02 sec)
66+
```
67+
4868
## MySQL compatibility
4969

50-
* Several of the `CREATE` options are not yet supported by TiDB, and will be parsed but ignored.
70+
The following `CREATE USER` options are not yet supported by TiDB, and will be parsed but ignored:
71+
72+
* TiDB does not support `WITH MAX_QUERIES_PER_HOUR`, `WITH MAX_UPDATES_PER_HOUR`, and `WITH MAX_USER_CONNECTIONS` options.
73+
* TiDB does not support the `DEFAULT ROLE` option.
74+
* TiDB does not support `PASSWORD EXPIRE`, `PASSWORD HISTORY` or other options related to password.
75+
* TiDB does not support the `ACCOUNT LOCK` and `ACCOUNT UNLOCK` options.
5176

5277
## See also
5378

sql-statements/sql-statement-drop-user.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/drop-user/']
88
# DROP USER
99

1010
This statement removes a user from the TiDB system database. The optional keyword `IF EXISTS` can be used to silence an error if the user does not exist.
11+
This statement requires the `CREATE USER` privilege.
1112

1213
## Synopsis
1314

@@ -25,10 +26,10 @@ This statement removes a user from the TiDB system database. The optional keywor
2526
mysql> DROP USER idontexist;
2627
ERROR 1396 (HY000): Operation DROP USER failed for idontexist@%
2728

28-
mysql> DROP USER IF EXISTS idontexist;
29+
mysql> DROP USER IF EXISTS 'idontexist';
2930
Query OK, 0 rows affected (0.01 sec)
3031

31-
mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
32+
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
3233
Query OK, 1 row affected (0.02 sec)
3334

3435
mysql> GRANT ALL ON test.* TO 'newuser';
@@ -54,10 +55,10 @@ mysql> SHOW GRANTS FOR 'newuser';
5455
+-------------------------------------+
5556
1 row in set (0.00 sec)
5657

57-
mysql> DROP USER newuser;
58+
mysql> DROP USER 'newuser';
5859
Query OK, 0 rows affected (0.14 sec)
5960

60-
mysql> SHOW GRANTS FOR newuser;
61+
mysql> SHOW GRANTS FOR 'newuser';
6162
ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'
6263
```
6364

sql-statements/sql-statement-flush-privileges.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/flush-privileges/']
88
# FLUSH PRIVILEGES
99

1010
This statement triggers TiDB to reload the in-memory copy of privileges from the privilege tables. You should execute `FLUSH PRIVILEGES` after making manual edits to tables such as `mysql.user`. Executing this statement is not required after using privilege statements such as `GRANT` or `REVOKE`.
11+
Executing this statement requires the `RELOAD` privilege.
1112

1213
## Synopsis
1314

sql-statements/sql-statement-grant-privileges.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/grant-privileges/']
88
# `GRANT <privileges>`
99

1010
This statement allocates privileges to a pre-existing user in TiDB. The privilege system in TiDB follows MySQL, where credentials are assigned based on a database/table pattern.
11+
Executing this statement requires the `GRANT OPTION` privilege and all privileges you allocate.
1112

1213
## Synopsis
1314

@@ -42,7 +43,7 @@ This statement allocates privileges to a pre-existing user in TiDB. The privileg
4243
## Examples
4344

4445
```sql
45-
mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
46+
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
4647
Query OK, 1 row affected (0.02 sec)
4748

4849
mysql> GRANT ALL ON test.* TO 'newuser';

sql-statements/sql-statement-revoke-privileges.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/revoke-privileges/']
88
# `REVOKE <privileges>`
99

1010
This statement removes privileges from an existing user.
11+
Executing this statement requires the `GRANT OPTION` privilege and all privileges you revoke.
1112

1213
## Synopsis
1314

@@ -42,7 +43,7 @@ This statement removes privileges from an existing user.
4243
## Examples
4344

4445
```sql
45-
mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
46+
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
4647
Query OK, 1 row affected (0.02 sec)
4748

4849
mysql> GRANT ALL ON test.* TO 'newuser';
@@ -68,10 +69,10 @@ mysql> SHOW GRANTS FOR 'newuser';
6869
+-------------------------------------+
6970
1 row in set (0.00 sec)
7071

71-
mysql> DROP USER newuser;
72+
mysql> DROP USER 'newuser';
7273
Query OK, 0 rows affected (0.14 sec)
7374

74-
mysql> SHOW GRANTS FOR newuser;
75+
mysql> SHOW GRANTS FOR 'newuser';
7576
ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'
7677
```
7778

sql-statements/sql-statement-set-password.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Query OK, 0 rows affected (0.01 sec)
2424
mysql> CREATE USER 'newuser' IDENTIFIED BY 'test';
2525
Query OK, 1 row affected (0.00 sec)
2626

27-
mysql> SHOW CREATE USER newuser;
27+
mysql> SHOW CREATE USER 'newuser';
2828
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2929
| CREATE USER for newuser@% |
3030
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -35,7 +35,7 @@ mysql> SHOW CREATE USER newuser;
3535
mysql> SET PASSWORD FOR newuser = 'test';
3636
Query OK, 0 rows affected (0.01 sec)
3737

38-
mysql> SHOW CREATE USER newuser;
38+
mysql> SHOW CREATE USER 'newuser';
3939
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4040
| CREATE USER for newuser@% |
4141
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -46,7 +46,7 @@ mysql> SHOW CREATE USER newuser;
4646
mysql> SET PASSWORD FOR newuser = PASSWORD('test'); -- deprecated syntax from earlier MySQL releases
4747
Query OK, 0 rows affected (0.00 sec)
4848

49-
mysql> SHOW CREATE USER newuser;
49+
mysql> SHOW CREATE USER 'newuser';
5050
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
5151
| CREATE USER for newuser@% |
5252
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+

0 commit comments

Comments
 (0)