maxhb
maxhb

Reputation: 8865

Export data modified after given date

I have a database where each table has two columns that indicate when a table row has been created (gen_date) or modified (mod_date).

I would like to export this complete database (structure) but would like to include only the data modified after a given date.

At the moment I use mysqldump to export the data:

mysqldump --user=username --password=password mydatabase

This exports all data and the table definitions.

Question: Is it possible to export only data with mod_date > some given date?

I was thinking about "cloning" the database and then delete all outdated data and use mysqldump to export the remaining data.

Example of a table:

CREATE TABLE `brand` (
  `id` int(11) UNSIGNED NOT NULL,
  `brand` tinytext CHARACTER SET utf8 COLLATE utf8_unicode_ci,
  `gen_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `mod_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Upvotes: 2

Views: 1303

Answers (1)

Chaoley
Chaoley

Reputation: 1302

Try something like this

mysqldump --user=username --password=password mydatabase mytable --no_create_info --where mod_date >= '2016-03-01' > mytable.sql

Upvotes: 2

Related Questions