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

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

WBOY
Release: 2016-06-01 13:00:45
Original
1013 people have browsed it

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

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

Copy after login

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

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

Copy after login

这时候就可以备份出mytable表中 id< 10000 的所有记录了。假设我们还想加一个时间范围条件,例如:

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

Copy after login

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

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

Copy after login

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

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

Copy after login
Copy after login

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

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

Copy after login
Copy after login

也就是变成了:

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

Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template