Mysql – How to synchronize two MySql tables using command line

data synchronizationMySQL

I have two tables in the same database (MySql) where one has been populated and there are data been added to it frequently.

I want to have the data added to the first table to be present in the other (synchronized) using a MySql command in console (without any other methods such as triggers, events etc.)

Is this possible and if so what is the command?

Best Answer

This can be achieved using a mysql replace into feature provided you have either primary key or unique key implemented on both table to eradicate duplicates. Replace into have similar syntax as of insert into as when key is present on table it first delete the old row and insert the coming one.

mysql>Replace into table2 select * from table1

Either have cron job or you can use mysql event scheduler to populate the data to other table according to your desired timings.

Hope it helps