MySQL

MySQL – mysqldump WHERE clause

The mysqldump utility allows you to backup a database and/or an individual table. The mysqldump generates the CREATE TABLE statements along with the INSERT statements to populate the table. This is extremely useful as it allows information to be applied to whatever MySQL residing on whatever host platform.

One of the features of the MySQL mysqldump utility is to adapt the individual queries in order to limit the rows selected in the backup. This is achieved with the “-w” or “–where” which appends the same WHERE clause on each of the tables.

So how does this work. Well if we have a table t1date with the following rows:

We can use the mysqldump utility to dump a selection of the records. For example, we want to backup only rows where “sdate” is between the Jan-02 and Jan-09. This should only give us one record (id = 4).