title | summary | toc |
---|---|---|
RENAME DATABASE |
The RENAME DATABASE statement changes the name of a database. |
false |
The RENAME DATABASE
statement changes the name of a database.
{% include sql/diagrams/rename_database.html %}
Only the root
user can rename databases.
Parameter | Description |
---|---|
name |
The first instance of name is the current name of the database. The second instance is the new name for the database. The new name must be unique and follow these identifier rules. |
> SHOW DATABASES;
+----------+
| Database |
+----------+
| db1 |
| db2 |
| system |
+----------+
> ALTER DATABASE db1 RENAME TO db3;
RENAME DATABASE
> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2 |
| db3 |
| system |
+----------+
> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2 |
| db3 |
| system |
+----------+
> ALTER DATABASE db2 RENAME TO db3;
pq: the new database name "db3" already exists