-
Notifications
You must be signed in to change notification settings - Fork 710
sql statement: add document for SET ROLE #2825
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
532f2af
add document for SET ROLE
cfee656
add media
01d930b
address comment
16abc5c
Merge branch 'master' into SetRoleEnglish
yikeke 6e1c306
Update sql-statements/sql-statement-set-role.md
339876b
Update sql-statements/sql-statement-set-role.md
33c5d08
Update sql-statements/sql-statement-set-role.md
0650045
Update sql-statements/sql-statement-set-role.md
9a5e641
Update sql-statements/sql-statement-set-role.md
02daf2d
Update sql-statements/sql-statement-set-role.md
906ddf7
Merge branch 'master' into SetRoleEnglish
d39ebd2
Merge branch 'master' into SetRoleEnglish
ti-srebot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,113 @@ | ||
| --- | ||
| title: SET ROLE | TiDB SQL Statement Reference | ||
| summary: An overview of the usage of SET ROLE for the TiDB database. | ||
| category: reference | ||
| --- | ||
|
|
||
| # SET ROLE | ||
|
|
||
| The `SET ROLE` statement is used to enable roles in the current session. After enabling roles, users can use the privileges of the role(s). | ||
|
|
||
| ## Synopsis | ||
|
|
||
| **SetRoleStmt:** | ||
|
|
||
|  | ||
|
|
||
| **SetRoleOpt:** | ||
|
|
||
|  | ||
|
|
||
| **SetDefaultRoleOpt:** | ||
|
|
||
|  | ||
|
|
||
| ## Examples | ||
|
|
||
| Create a user `'u1'@'%'` and three roles: `'r1'@'%'`, `'r2'@'%'` and `'r3'@'%'`. | ||
| Grant these roles to `'u1'@'%'` and set `'r1'@'%'` as the defualt role of `'u1'@'%'`. | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| CREATE USER 'u1'@'%'; | ||
| CREATE ROLE 'r1', 'r2', 'r3'; | ||
| GRANT 'r1', 'r2', 'r3' TO 'u1'@'%'; | ||
| SET DEFAULT ROLE 'r1' TO 'u1'@'%'; | ||
| ``` | ||
|
|
||
| Log in as `'u1'@'%'` and execute the following `SET ROLE` statement to enable all roles. | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| SET ROLE ALL; | ||
| SELECT CURRENT_ROLE(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +----------------------------+ | ||
| | CURRENT_ROLE() | | ||
| +----------------------------+ | ||
| | `r1`@`%`,`r2`@`%`,`r3`@`%` | | ||
| +----------------------------+ | ||
| 1 row in set (0.000 sec) | ||
| ``` | ||
|
|
||
| Execute the following `SET ROLE` statement to enable `'r2'` and `'r3'`. | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| SET ROLE 'r2', 'r3'; | ||
| SELECT CURRENT_ROLE(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +-------------------+ | ||
| | CURRENT_ROLE() | | ||
| +-------------------+ | ||
| | `r2`@`%`,`r3`@`%` | | ||
| +-------------------+ | ||
| 1 row in set (0.000 sec) | ||
| ``` | ||
|
|
||
| Execute the following `SET ROLE` statement to enable the default role(s). | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| SET ROLE DEFAULT; | ||
| SELECT CURRENT_ROLE(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +----------------+ | ||
| | CURRENT_ROLE() | | ||
| +----------------+ | ||
| | `r1`@`%` | | ||
| +----------------+ | ||
| 1 row in set (0.000 sec) | ||
| ``` | ||
|
|
||
| Execute the following `SET ROLE` statement to cancel all enabled role(s). | ||
|
|
||
| {{< copyable "sql" >}} | ||
|
|
||
| ```sql | ||
| SET ROLE NONE; | ||
| SELECT CURRENT_ROLE(); | ||
| ``` | ||
|
|
||
| ``` | ||
| +----------------+ | ||
| | CURRENT_ROLE() | | ||
| +----------------+ | ||
| | | | ||
| +----------------+ | ||
| 1 row in set (0.000 sec) | ||
| ``` | ||
|
|
||
| ## See also | ||
|
|
||
| * [Role-Based Access Control](/role-based-access-control.md) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.