The following command exports a MySQL database allowing to import the result in a second DB without dropping the existing tables.

mysqldump --single-transaction --no-create-info --insert-ignore DB TABLE --where="EXISTS(SELECT 1 FROM TABLE_NAME WHERE COLLUMN_NAME__datetime > now() - interval 6 month)" | pv | gzip > DUMPDB.sql.gz
pv DUMP.sql.gz | gunzip | mysql --force dbname
Share This