Merge two MySQL databases

To copy data from a table to another table in two MySQL databases, both the databases need to exist on the same account.

Method 1: Using Cpanel

  1. From cPanel, click on phpMyAdmin icon.

  2. Click on the SQL tab at the top. You will see where it says, 'Run SQL query/queries on server "localhost":'

  3. In the text box below that, insert the following code, but replace DB1 and DB2 with the database names. Also, replace TABLE1 with the table name you are trying to merge.
INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1
  1. Click on Go button.

  2. Repeat for any other tables you want to merge.

Method 2. Through Shell (SSH)

  1. From SSH, you need to type the command to access mysql. Here is the format, but replace MYNAME with your username and PASS with your password.
  2. mysql -u MYNAME -pPASS
  3. Now type the following code, but replace DB1 and DB2 with the database names. Also, replace TABLE1 with the table name you are trying to merge.
    INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1;
  4. Hit the Enter key.
  5. Repeat for any other tables you want to merge.
Note: Use REPLACE INTO instead of INSERT INTO to have the data from DB2 overwrite the data in DB1 if they share a primary/unique key.

Comments

Popular posts from this blog

SVN: File remains in conflict

HowTo: Enable extended logging for exim

12 tweakings for WHM/cPanel to speed up WordPress