Mysql – Rename the database name through terminal

MySQL

My database name is studenttRecord. I would like to correct the spelling to studentRecord. How can I change it if possible?

Best Answer

Firstly, create the new database with the command;

mysql> CREATE DATABASE studentRecord;

Then transfer the contents from the old database into the new database;

shell$ mysqldump --opt studenttRecord | mysql studentRecord

(add in the username and password bits as appropriate)

The --opt part will add a number of standard flags to the data dump, and I refer you to the MySQl documentation for more information.

Once the transfer is complete, and you have verified it, you can drop your old database.

If your database is particularly huge, this can take some time to perform, so an alternative is to RENAME TABLE for each of the tables in the old database, and move them into the new database.

Create the database as above, then for each table do the following;

mysql> RENAME TABLE studenttRecord.table_name TO studentRecord.table_name;

Replacing table_name with each of your tables in turn (create a script of this in a text editor to help prepare a complete list!).

Hope that helps, Dave