1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to import sql file and force update tables?

Discussion in 'MySQL' started by postcd, Feb 27, 2014.

  1. #1
    Hello,

    i have mysql database with default tables and default data and i also have second database which contains new data.

    I want to add this new data into default database.

    I mean when i import new database .sql file, data are not aded becasue tables exist

    please how can i

    1) replace all data by imported data
    2) add only data that dont exist in tables

    possibly without doing new mysql export? If new export is required, please how the command will look like so it supports update?
     
    postcd, Feb 27, 2014 IP
  2. HassanKhalid

    HassanKhalid Active Member

    Messages:
    158
    Likes Received:
    6
    Best Answers:
    4
    Trophy Points:
    90
    #2
    Merge two MySQL databases

    The easiest way I can explain this is show you how to copy data from a table to another table.

    Both databases need to exist on the same account. If they do not, you will need to create a backup of one and move it. (If both databases have the same name, you will need to also rename one before moving).

    Once both are on the same account, login to either SSH or cPanel.

    cPanel
    1. From cPanel, you need to click the phpMyAdmin icon.
    2. Click 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
      Code (markup):
    4. Click the Go button.
    5. Repeat for any other tables you want to merge.
    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
      Code (markup):
    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;
      Code (markup):
    4. Hit the Enter key.
    5. Repeat for any other tables you want to merge.
     
    HassanKhalid, Feb 27, 2014 IP