HelpSpa.com

Free Computer Tutorials, Computer Tutorial Videos and Commentary

Main Navigation

RSS Feed RSS Feed

MySql: How to Change the Database Name

 

Once you’ve created a 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;

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.

USE newDatabase;

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!

Leave a Reply

You must be logged in to post a comment.

Bookmark and Share