Skip to content

Latest commit

 

History

History
87 lines (72 loc) · 1.53 KB

rename-database.md

File metadata and controls

87 lines (72 loc) · 1.53 KB
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.

Synopsis

{% include sql/diagrams/rename_database.html %}

Required Privileges

Only the root user can rename databases.

Parameters

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.

Examples

Rename a Database

> SHOW DATABASES;
+----------+
| Database |
+----------+
| db1      |
| db2      |
| system   |
+----------+
> ALTER DATABASE db1 RENAME TO db3;
RENAME DATABASE
> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2      |
| db3      |
| system   |
+----------+

Rename Fails (New Name Already In Use)

> SHOW DATABASES;
+----------+
| Database |
+----------+
| db2      |
| db3      |
| system   |
+----------+
> ALTER DATABASE db2 RENAME TO db3;
pq: the new database name "db3" already exists

See Also