Moving Tables from One MySQL Database to Another Using Command Line Interface

Moving all of the tables from one mysql database to another is very easy. It can be done using phpMyAdmin to dump the database to a .sql file. However, in this tutorial, we are going to dump the database to a .sql file using the command line interface. With the command line, you can complete your task more faster compare to the phpMyAdmin method.

In order to start, you need to be a user who has full privileges in both the databases or should be a root user. Usually, it is not necesssary to use username and password when dumping a mysql database in Linux cPanel Hosting. It won’t prompt you for the password and automatically takes the username and password. Follow the below steps:

How to Dump the MySQL Database to an SQL file #

Enter the following command to dump a database:

mysqldump database_name > Database_name.sql

For example, suppose you wanted to dump a database called “blog”.

mysqldump blog > blog.sql

Now, since you have the database backup ready, simply import the contents to your destination database (i.e. another database).

mysql new_database_name < Database_name.sql

Here we are going to use the new destination database known as “new blog”.

For Example:

mysql new blog < blog.sql

Once the transfer is completed, you will see two databases that are similar, but with different names.

Powered by BetterDocs