This MySQL statement does what it says: it will rename a database to whatever name you give it, provided it doesn't already exist.


Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

RENAME {DATABASE|SCHEMA} database TO database[,...]


Use this MySQL statement to rename a given database in MySQL to a new name, given after the TO keyword. While a database is being renamed with this statement, no other client can interact with the database involved. MySQL tables that are currently locked or tables that are part of a transaction in progress cannot be renamed. This statement was added in version 5.1.7 of MySQL. As of version 5.0.2 of MySQL, the keyword DATABASE is synomymous with SCHEMA.


Below is an example of this MySQL statement:

RENAME DATABASE personnel TO human_resources;

In this example, the name of the database called personnel was changed to human_resources to coincide with a renaming of the department to which it relates. All of the tables and data are the same and continue to exist in the directory with the new database name.