Unsupported Screen Size: The viewport size is too small for the theme to render properly.

Merging Two Mysql Databases

forums forums SQLyog SQLyog: Bugs / Feature Requests Merging Two Mysql Databases

  • This topic is empty.
Viewing 8 reply threads
  • Author
    Posts
    • #11970
      Chandru
      Member

      Hi,

      I have two mysql databases (same schema)for example DB1 and DB2.

      Can webyog be used to merge these two databases into one database? i.e DB1 + DB2 = DB3.

      If yes, please provide steps/doc to try out in trial version of the webyog tool.

      Thanks in advace,

      Chandru

    • #30851
      navyashree.r
      Member

      Hi Chandru,

      Please post in right category as this is related to 'SQLyog' and I am moving this topic to “SQLyog Bugs and Features” section.

      Regards,

      Navya

    • #30852
      navyashree.r
      Member

      Chandru,

      To merge 2 MySQL databases into one you can use “Database Synchronization” or simply use “Copy database to different host/database”.

      Quote:
      Can webyog be used to merge these two databases into one database? i.e DB1 + DB2 = DB3.

      To do this first create “DB3” database where you need to copy tables and their datas from DB1 and DB2 into DB3.

      A. Using “Database Synchronization” tool from Powertools Menu. (right now we are supporting for single database only at a time):

      To perform this first select Source db “DB1” and Target db “DB3” and similarly “DB2” to “DB3” by checking option 'One way synchronization'.

      You can select 'Generate script' option from the wizard as shown in image “data sync.JPG” and edit the script in any editor by selecting only UPDATE statements. You may run Data Sync between master asand slave as , any difference between master and slave will result in INSERTs/UPDATEs/DELETEs on slave.

      FYI,

      Read the FAQ links given below,

      http://www.webyog.com/faq/content/27/114/en/introduction-to-the-_sqlyog-job-agent_-sja.html

      Also, to understand data sync in depth please read this article:

      http://webyog.com/en/whitepapers/Using_SQLyog_Enterprise_to_Effectively_Synchronize_MySQL_Databases.pdf

      (but note this article is not up-to-date, but principles are the same).

      Additionally, a very important point to notice is that the Primary Key on every table must be defined in such a way that the same value for the PK will never be created for different data on different hosts.

      B. Another option is to use “Copy database to different host/database”. First select source DB1 and target DB3 and copy the data. Similarly follow same to copy from DB2 to DB3.

      You can go through our Help document too.

      Regards,

      Navya

    • #30853
      Chandru
      Member
      Quote:

      To do this first create “DB3” database where you need to copy tables and their datas from DB1 and DB2 into DB3.

      A. Using “Database Synchronization” tool from Powertools Menu. (right now we are supporting for single database only at a time):

      To perform this first select Source db “DB1” and Target db “DB3” and similarly “DB2” to “DB3” by checking option 'One way synchronization'.

      You can select 'Generate script' option from the wizard as shown in image “data sync.JPG” and edit the script in any editor by selecting only UPDATE statements. You may run Data Sync between master asand slave as , any difference between master and slave will result in INSERTs/UPDATEs/DELETEs on slave.

      FYI,

      Read the FAQ links given below,

      http://www.webyog.co…agent_-sja.html

      Also, to understand data sync in depth please read this article:

      http://webyog.com/en…L_Databases.pdf

      (but note this article is not up-to-date, but principles are the same).

      Additionally, a very important point to notice is that the Primary Key on every table must be defined in such a way that the same value for the PK will never be created for different data on different hosts.

      B. Another option is to use “Copy database to different host/database”. First select source DB1 and target DB3 and copy the data. Similarly follow same to copy from DB2 to DB3.

      You can go through our Help document too.

      Regards,

      Navya

      Navya,

      Thanks for detailed information.

      In fact I will having the exact scenario as you mentioned above. i.e Same Primary Key(PK) in DB1 and DB2 tables will have the different data.

      The below example will give you a clear picture and let me know is any way we can achieve this using SQLyog tool.

      Example:


      If you observe in below table, the same PK's will have different data in tables DB1:animalTable and DB2:animalTable. So, my expectation from the tool would be the DB3 (DB1 + DB2) will have cumulative data from DB1 and DB2.

      DB1:animalTable


      PK | Name |


      1 | frog |


      2 | ant |


      DB2:animalTable


      PK | Name |


      1 | dog |


      2 | fish |


    • #30854
      navyashree.r
      Member

      Chandru,

      Quote:
      So, my expectation from the tool would be the DB3 (DB1 + DB2) will have cumulative data from DB1 and DB2.

      Can you explain what you meant by 'cumulative data'? Is this is the case you are expecting your resultset to be:

      DB3:animalTable


      PK | Name |


      1 | frog |


      2 | ant |


      3 | dog |


      4 | fish |


      Sorry, if wrong please explain what way you are expecting your data to be?

      Thank You in advance.

      Navya

    • #30855
      Chandru
      Member
      'navyashree.r' wrote on '17:

      Chandru,

      Can you explain what you meant by 'cumulative data'? Is this is the case you are expecting your resultset to be:

      DB3:animalTable


      PK | Name |


      1 | frog |


      2 | ant |


      3 | dog |


      4 | fish |


      Sorry, if wrong please explain what way you are expecting your data to be?

      Thank You in advance.

      Navya

      Yes. Also, all dependent tables (if any) should be aware of this change to the PK in table. Ex: In DB2:animalTable the PK for Dog and Fish is 1 and 2 . After DB3 creation, it becomes 3 and 4.

      FYI: I forget to mention in my last post that I tried the “Database Synchronization” tool from Powertools Menu and seems it is overwriting the table each time when I synchronise DBs during above scenario. I did not try “Copy database to different host/database” yet.

      Hope this info will helps you. Also, is any contact number where I can directly call up and have a discussion ?

      Thanks,

      Chandru

    • #30856
      Chandru
      Member
      'Chandru' wrote on '17:

      Yes. Also, all dependent tables (if any) should be aware of this change to the PK in table. Ex: In DB2:animalTable the PK for Dog and Fish is 1 and 2 . After DB3 creation, it becomes 3 and 4.

      FYI: I forget to mention in my last post that I tried the “Database Synchronization” tool from Powertools Menu and seems it is overwriting the table each time when I synchronise DBs during above scenario. I did not try “Copy database to different host/database” yet.

      Hope this info will helps you. Also, is any contact number where I can directly call up and have a discussion ?

      Thanks,

      Chandru

      One more important point…Please note that all dependent tables of animalTable (references) should be updated accordingly.

      Thanks,

      Chandru

    • #30857
      navyashree.r
      Member

      Chandru,

      Quote:
      Yes. Also, all dependent tables (if any) should be aware of this change to the PK in table. Ex: In DB2:animalTable the PK for Dog and Fish is 1 and 2 . After DB3 creation, it becomes 3 and 4.

      You can use 'IMPORT EXTERNAL DATA TOOL' from Powertools menu or simply click CTRL+ALT+O. Follow the steps to achieve your result:

      1. You have created 2 databases with tables (DB1 and DB2) and empty database (DB3).

      2. Open 'IMPORT EXTERNAL DATA TOOL' from Powertools menu.

      3. Create a new MySQL DSN for DB1. See image 'mysqldsn.jpg'. Similarly to Db2.

      4. Select the target database DB3 to import data from first database DB1.

      5. Now select tables and run the task to import data to DB3.

      Now, you have successfully transferred data and their table from DB1 to DB3. Open table from DB3 in TABLE DATA tab to view the data.

      6. Now again open 'IMPORT EXTERNAL DATA TOOL' from Powertools menu and select MySQL DSN for DB2.

      7. Select target DB3 to import data from DB2.

      8. In 'Select Table(s)' –> Map wizard, uncheck PRIMARY COLUMN from wizard. See image 'mapping.jpg'.

      9. Open 'Select Table(s)' –> Advanced options wizard. Select 'import into existing' and 'keep target data' options from wizard. See image advancedoptions.jpg'.

      10. Run the task.

      For output see image 'tabledata.jpg'. You will get the resultset as expected.

      Read our program help file for more info.

      Thanks.

      Navya

    • #30858
      peterlaursen
      Participant

      But if you have auto_increment Primary keys you should dump from the RESULT tab using a result set without that column.  Also with UNIQUE and FOREIGN KEY constraints it may not be so simple.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.