The RENAME USER statement can be used in MySQL if a MySQL administrator wants to change the username or the host of an existing MySQL user account without altering the user account’s privileges.
RENAME USER 'username'@'host' TO 'new_username'@'host';
- Username: It is the username of the user account you want to rename.
- new_username: It is the new name you want to assign to the user.
Suppose there are 4 users in the MySQL database server as listed below:
Let us now learn about how to rename users using RENAME USER statement:
Renaming a single user using the RENAME USER statement: To rename the user account with the username “gfguser1”, the RENAME USER statement should be executed as follows:
Table after execution of the rename user statement will be as follows:
Renaming multiple users using the RENAME USER statement: The RENAME USER statement can be used to rename multiple user accounts at once. To rename two user account “gfguser2” and “gfguser1” from the table mentioned above,the RENAME USER statement should be executed as follows:
Table after execution of the above rename user statement will be as follows:
- MySQL | DROP USER
- Mysql | User-defind Variables
- MySQL | Change User Password
- MySQL | CREATE USER Statement
- MySQL | Common MySQL Queries
- SQL | ALTER (RENAME)
- MongoDB vs MySQL
- How to get ID of the last updated row in MySQL?
- MySQL | BIN() Function
- IFNULL in MySQL
- PHP | MySQL WHERE Clause
- MySQL | LEAD() and LAG() Function
- MySQL | Group_CONCAT() Function
- MySQL | Hexadecimal Literals
- Mathematical functions in MySQL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.