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.
Syntax :
RENAME USER 'username'@'host' TO 'new_username'@'host';
Parameters Used:
-
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:
Syntax:

Output:
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:
Syntax:

Output:
Table after execution of the above rename user statement will be as follows:

Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our
Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.
Ready to dive in? Explore our Free Demo Content and join our
Complete Interview Preparation course.
Last Updated :
03 Mar, 2018
Like Article
Save Article