RENAME USER

2023-08-18 09:26:34  Updated

Description

You can execute the RENAME USER statement to change the username that is used to log on to the ApsaraDB for OceanBase system. Note

To execute this statement, ensure you have the global CREATE USER permission.

Syntax

RENAME USER 
'oldusername' TO 'newusername'
[,'oldusername' TO 'newusername'...] ;

Parameters

Parameter Description
oldusername The old username.
newusername The new username. The name must be a maximum of 16 bytes in length.
'oldusername' TO 'newusername' Changes the username. To change multiple usernames at a time, separate them with commas (,). After you change the username, the permissions of the user remain unchanged.

Examples

  1. Before you change a username, execute the following statement to view users:
SELECT user FROM mysql.user;

Output:

mysql> SELECT user FROM mysql.user;
+-----------+
| user      |
+-----------+
| root      |
| admin     |
| sqluser01 |
| sqluser02 |
+-----------+
4 rows in set (0.00 sec)
  1. Execute the following statement to change username sqluser01 to obsqluser01.
RENAME USER 'sqluser01' TO 'obsqluser01';
  1. After you change the username, execute the following statement to view users:
SELECT user FROM mysql.user;

Output: Username sqluser01 is changed to obsqluser01.

mysql> RENAME USER 'sqluser01' TO 'obsqluser01';
Query OK, 0 rows affected (0.04 sec)

mysql> SELECT user FROM mysql.user;
+-------------+
| user        |
+-------------+
| root        |
| admin       |
| obsqluser01 |
| sqluser02   |
+-------------+
4 rows in set (0.00 sec)

Contact Us