MySQL: How to Change the Database Name
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.
CREATE DATABASE newDatabase;
newDatabase is the name of the new (renamed) database.
3. Use the USE command to make sure you are working with the new database.
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!
We are currently offering a free copy of our 16-page eBook, "How to Organize your Digital Photography Collection" to everyone who signs up for our free newsletter. This eBook will review how to organize your digital photos, discuss metadata, and give you an overview of software than can help you with your digital photography workflow. Sign up in the signup area, located in the right-side column of every page on this site, and read your copy now!