Rename a MySQL database

Once day you want to rename your database in MySQL for whatever reason. How can you do this idea?

via phpMyAdmin

From phpMyAdmin, we often rename a database by applying the following steps:

  1. Select database on the left side bar/tree or in Databases tab.
  2. Click on Operations tab.
  3. Type a new name for the database in the text box along with the label Rename database to,
  4. Click Go button to process the operation.

See the inserted image as below for your reference.

Rename database in phpmyadmin
Rename database in phpmyadmin

via MySQL Command Line

[box type=”info” align=”aligncenter” ]In principle, export structure and data of the database that you want to rename, then create a fresh one and append all the newly exported data to the new one. Finally, delete the old database.[/box]

  1. Export structure and data of the database which is going to rename.
    mysqldump -u a_given_username -p the_database > dbexport.sql
  2. Log in to your MySQL Server from a terminal.
    mysql -u a_given_username -p
  3. Create a fresh database
    CREATE DATABASE new_database;
  4. Import structure and data to the newly created database.
    mysql -u a_given_username -p new_database < dbexport.sql
  5. Delete the old database
    DROP DATABASE the_database;

Finish!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.