Once you’ve created a MySQL database and named it you cannot rename the database using standard SQL commands such as ALTER
in the same manner as you would rename a table. The way to rename a database is as simple as creating a new, empty database, and then recreating the old database in this new database.
Here are the detailed steps:
1. Run a mysqldump
on the existing database. Let’s assume you named the export file myDatabase.sql
. For instructions how to do this see my post about running the mysqldump command.
2. Create a new database using the create database command.
[shell]CREATE DATABASE newDatabase;[/shell]
where newDatabase
is the name of the new (renamed) database.
3. Use the USE command to make sure you are working with the new database.
[shell]USE newDatabase;[/shell]
4. Execute the .sql script you generated in step 1 from the old database — which is easiest to do from phpMyAdmin or from the query browser.
Don’t forget to add “;” to end your statements.
Presto! You now have a renamed database!