13.1.9. RENAME DATABASE
Syntax
RENAME {DATABASE | SCHEMA} db_name
TO new_db_name
;
This statement renames a database. It requires the
ALTER
and DROP
privileges
for the database, and the CREATE
privilege
for the new database. RENAME SCHEMA
is a
synonym for RENAME DATABASE
.
When the server receives this statement, it creates a new
database. Then it moves tables and other database objects such
as triggers to the new database. It also updates the
Db
column in the system tables for objects
such as stored routines and events. Finally, the server drops
the old database.
Note that currently there are these
limitations:
RENAME DATABASE
does not change any
account privileges listed in the system tables. This needs
to be changed manually.
-
RENAME DATABASE
does not migrate any
stored routines or events to the new schema name. This
means that:
For stored routines, it does not change any values
in the ROUTINE_SCHEMA
column of
the INFORMATION_SCHEMA.ROUTINES
table, or in the db
column of the
mysql.proc
table.
For events, it does not change any values in the
EVENT_SCHEMA
column of the
INFORMATION_SCHEMA.EVENTS
table,
or in the db
column of the
mysql.event
table.
This statement was added in MySQL 5.1.7.