Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 26 additions & 1 deletion sql-statements/sql-statement-create-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,42 @@ This statement creates a new user, specified with a password. In the MySQL privi

## Examples

Create a user with the `newuserpassword` password.

```sql
mysql> CREATE USER 'newuser' IDENTIFIED BY 'newuserpassword';
Query OK, 1 row affected (0.04 sec)
```

Create a user who can only log in to `192.168.1.1`.

```sql
mysql> CREATE USER 'newuser2'@'192.168.1.1' IDENTIFIED BY 'newuserpassword';
Query OK, 1 row affected (0.02 sec)
```

Create a user who is enforced to log in using TLS connection.

```sql
CREATE USER 'newuser3'@'%' REQUIRE SSL IDENTIFIED BY 'newuserpassword';
Query OK, 1 row affected (0.02 sec)
```

Create a user who is required to use X.509 certificate at login.

```sql
CREATE USER 'newuser4'@'%' REQUIRE ISSUER '/C=US/ST=California/L=San Francisco/O=PingCAP' IDENTIFIED BY 'newuserpassword';
Query OK, 1 row affected (0.02 sec)
```

## MySQL compatibility

* Several of the `CREATE` options are not yet supported by TiDB, and will be parsed but ignored.
The following `CREATE USER` options are not yet supported by TiDB, and will be parsed but ignored:

* TiDB does not support `WITH MAX_QUERIES_PER_HOUR`, `WITH MAX_UPDATES_PER_HOUR`, and `WITH MAX_USER_CONNECTIONS` options.
* TiDB does not support the `DEFAULT ROLE` option.
* TiDB does not support `PASSWORD EXPIRE`, `PASSWORD HISTORY` or other options related to password.
* TiDB does not support the `ACCOUNT LOCK` and `ACCOUNT UNLOCK` options.

## See also

Expand Down
9 changes: 5 additions & 4 deletions sql-statements/sql-statement-drop-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/drop-user/']
# DROP USER

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.
This statement requires the `CREATE USER` privilege.

## Synopsis

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

mysql> DROP USER IF EXISTS idontexist;
mysql> DROP USER IF EXISTS 'idontexist';
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
Query OK, 1 row affected (0.02 sec)

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

mysql> DROP USER newuser;
mysql> DROP USER 'newuser';
Query OK, 0 rows affected (0.14 sec)

mysql> SHOW GRANTS FOR newuser;
mysql> SHOW GRANTS FOR 'newuser';
ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'
```

Expand Down
1 change: 1 addition & 0 deletions sql-statements/sql-statement-flush-privileges.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/flush-privileges/']
# FLUSH PRIVILEGES

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`.
Executing this statement requires the `RELOAD` privilege.

## Synopsis

Expand Down
3 changes: 2 additions & 1 deletion sql-statements/sql-statement-grant-privileges.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/grant-privileges/']
# `GRANT <privileges>`

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.
Executing this statement requires the `GRANT OPTION` privilege and all privileges you allocate.

## Synopsis

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

```sql
mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
Query OK, 1 row affected (0.02 sec)

mysql> GRANT ALL ON test.* TO 'newuser';
Expand Down
7 changes: 4 additions & 3 deletions sql-statements/sql-statement-revoke-privileges.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ aliases: ['/docs/stable/reference/sql/statements/revoke-privileges/']
# `REVOKE <privileges>`

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

## Synopsis

Expand Down Expand Up @@ -42,7 +43,7 @@ This statement removes privileges from an existing user.
## Examples

```sql
mysql> CREATE USER newuser IDENTIFIED BY 'mypassword';
mysql> CREATE USER 'newuser' IDENTIFIED BY 'mypassword';
Query OK, 1 row affected (0.02 sec)

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

mysql> DROP USER newuser;
mysql> DROP USER 'newuser';
Query OK, 0 rows affected (0.14 sec)

mysql> SHOW GRANTS FOR newuser;
mysql> SHOW GRANTS FOR 'newuser';
ERROR 1141 (42000): There is no such grant defined for user 'newuser' on host '%'
```

Expand Down
6 changes: 3 additions & 3 deletions sql-statements/sql-statement-set-password.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Query OK, 0 rows affected (0.01 sec)
mysql> CREATE USER 'newuser' IDENTIFIED BY 'test';
Query OK, 1 row affected (0.00 sec)

mysql> SHOW CREATE USER newuser;
mysql> SHOW CREATE USER 'newuser';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for newuser@% |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Expand All @@ -35,7 +35,7 @@ mysql> SHOW CREATE USER newuser;
mysql> SET PASSWORD FOR newuser = 'test';
Query OK, 0 rows affected (0.01 sec)

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

mysql> SHOW CREATE USER newuser;
mysql> SHOW CREATE USER 'newuser';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CREATE USER for newuser@% |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Expand Down