MySQL Tutorial MySQL Advanced MySQL Database Account Management MySQL References

MySQL - RENAME USER



The MySQL RENAME USER statement is used to rename a user in the MySQL database. An error occurs if user_name do not exist or new_name already exist in the database.

Syntax

The syntax of using RENAME USER statement in MySQL is given below:

RENAME USER 
  user_name TO new_name;

Parameters

user_name Required. Specify the name of the user to rename in the MySQL database.
new_name Required. Specify the new name to assign to the user_name.

Example: Rename a user

In the example below, the RENAME USER statement is used to rename a user called jeffrey to jeff in the MySQL database.

RENAME USER 
  'jeffrey'@'localhost' TO 'jeff'@'localhost';

Example: Rename more than one user

In the example below, two users are renamed in the MySQL database. First user is renamed from jeffrey to jeff and second user is renamed from matthew to matt.

RENAME USER
  'jeffrey'@'localhost' TO 'jeff'@'localhost',
  'matthew'@'localhost' TO 'matt'@'localhost';