MySQL - How to rename a Database

In this article I’m going to show you how to create a mysql dump and use it to rename your mysql database.

First of all, open the start bar, write cmd and run it as administrator by right-clicking on it. After that, navigate to the MySQL Server bin folder.
Once there, create a mysql dump:

  mysqldump -u username -p -R database_name > dbname.sql;
  • Replace the username, password and dbname;
  • Replace the name of the dump file (.sql).

Now, create a new database with the new name:

 mysqladmin -u username -p create new_dbname;

Make sure that the name is not already used. Enter the mysql shell with mysql.exe -u root -p and execute SHOW DATABASES. You can also use this command to check if the database was created correctly. To exit the shell, type exit.

Then, you have to import the dump in the newly created database:

mysql –u username –p new_dbname < dbname.sql;

The last step is to delete the old database:

 mysqladmin -u username –p drop dbname;

After creating the new database, you may have to grant the privileges back to some users. Read this article to see how.