Home >Database >Mysql Tutorial >在MySQLDump中使用-w语句进行备份的方法_MySQL

在MySQLDump中使用-w语句进行备份的方法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:00:451019browse

我们在用mysqldump备份数据时,有个选项是 –where / -w,可以指定备份条件,这个选项的解释是:

-w, --where=name  Dump only selected records. Quotes are mandatory

我们可以做个测试,例如:

mysqldump --single-transaction -w ' id < 10000 ' mydb mytable > mydump.sql

这时候就可以备份出mytable表中 id

mysqldump --single-transaction -w " id < 10000 and logintime < unix_timestamp('2014-06-01')" mydb mytable > mydump.sql

在这里,一定注意单引号和双引号问题,避免出现这种情况:

mysqldump --single-transaction -w ' id < 10000 and logintime < unix_timestamp('2014-06-01') ' mydb mytable > mydump.sql

这样的话,结果条件会被解析成:

WHERE id < 10000 and logintime < unix_timestamp(2014-06-01)

眼尖的同学会发现,时间条件变成了:

WHERE id < 10000 and logintime < unix_timestamp(2014-06-01)

也就是变成了:

unix_timestamp(2007) -- 2014-6-1 = 2007

这和我们原先的设想大相径庭,因此一定要谨慎。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn