The mysqldump plus w parameter is something to look out for when backing up data
- 2020-06-19 11:50:10
- OfStack
When we use mysqldump to back up data, we have the option "where / -w". We can specify the backup conditions.
-w, --where=name Dump only selected records. Quotes are mandatory
We can do a test like this:
mysqldump --single-transaction -w ' id < 10000 ' mydb mytable > mydump.sql
At this point, you can back up id in the mytable table < All records of 10000. Suppose we want to add another time range condition, for example:
mysqldump --single-transaction -w " id < 10000 and logintime < unix_timestamp('2014-06-01')" mydb mytable > mydump.sql
Here, 1 pay attention to single and double quotation marks to avoid this situation:
mysqldump --single-transaction -w ' id < 10000 and logintime < unix_timestamp('2014-06-01') ' mydb mytable > mydump.sql
In this case, the resulting condition is resolved to:
WHERE id < 10000 and logintime < unix_timestamp(2014-06-01)
Eagle-eyed students will find that the time conditions become:
WHERE id < 10000 and logintime < unix_timestamp(2014-06-01)
So it becomes:
unix_timestamp(2007)
This is quite different from what we thought, so be careful