Home | Work & Business | Legal | Name Changes | How to Change the Name of a MySQL Database

How to Change the Name of a MySQL Database

by Jeffrey Ober
  • Overview

    Changing the name of a database is a very uncommon occurrence. However, there are times when a database name just needs to be changed. MySQL had a command that was able to change the name of the database for a short time, but it was determined that the command was too risky and was a security risk, and the command was removed. Instead, to effectively change the name of a MySQL database, the database needs to be dumped and then re-created with a new name.
 
  • Step 1

    Open a shell program to obtain access to the MySQL installation and commands. This can be a command prompt on the local computer or a Telnet-type remote connection.
  • Step 2

    Use the mysqldump command to dump the contents of the current database into a file: mysqldump -u username -p -v olddatabasename > olddatabasenamedump.sql
  • Step 3

    Use the mysqladmin command to create a new database with the name needed for the new database: mysqladmin -u username -p create newdatabasename
  • Step 4

    Use the mysql command to upload the database dump into the newly created database: mysql -u username -p newdatabasename < olddatabasenamedump.sql
  • 5
  • You can delete the old database once you have tested the new database. You can also delete the SQL file created once the process is complete.
  • You can delete the old database once you have tested the new database.
  • You can also delete the SQL file created once the process is complete.

References & Resources