If a MySQL administrator wishes to change the username or host of an existing MySQL user account without changing the user account's privileges, the RENAME USER statement can be used in MySQL.
RENAME USER statement syntax:
RENAME USER 'username'@'host' TO 'new_username'@'host';
Parameters:
username: this is the username of the user account you want to rename.
new_username: This is the new name you want to assign to the user.
Suppose there are 4 users in the MySQL database server as follows:
Now let us understand how to use the RENAME USER statement Rename a user:
Rename a single user using the RENAME USER statement:
To rename a user account with the username "gfguser1", execute RENAME USER as follows Statement:
Syntax:
Output:
The table after executing the rename user statement is as follows:
Use the RENAME USER statement to rename multiple users:
The RENAME USER statement can be used to rename multiple user accounts at once. To rename the two user accounts "gfguser2" and "gfguser1" in the above table, the RENAME USER statement should be executed as follows:
Syntax:
Output:
The table after executing the above rename user statement is as follows:
## Recommended related mysql video tutorials: "mysql tutorial 》
This article is about the method of changing the user name in MySQL. I hope it will be helpful to friends in need!The above is the detailed content of How to modify username in MySQL? (code example). For more information, please follow other related articles on the PHP Chinese website!