MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB - RENAME USER



The MariaDB RENAME USER statement is used to rename a user in the MariaDB 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 MariaDB is given below:

RENAME USER 
  user_name TO new_name;

Parameters

user_name Required. Specify the name of the user to rename in the MariaDB 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 MariaDB database.

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

Example: Rename more than one user

In the example below, two users are renamed in the MariaDB 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';