Home / Information Systems / Database / Rename a MySQL database

Rename a MySQL database

Print Friendly, PDF & Email

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

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.
  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!

comments

About Admin

programming all time and taking a bread for the lunch hahaha... When you are engaging your work, nobody can attract you doing another thing. Otherwise, should should move to other jobs or are not interested in your job enough.