使用Mysql Dump备份视图 [英] Backing Up Views with Mysql Dump
问题描述
我只想使用mysqldump备份视图.
I want to back up only the Views with mysqldump.
这可能吗?
如果是,怎么办?
推荐答案
注意:此答案来自肯从建议的修改移至自己的答案.
NOTE: This answer from Ken moved from suggested edit to own answer.
这是使用上述内容的变体的完整命令行示例
here's a full command line example using a variant of the above
mysql -u username INFORMATION_SCHEMA
--skip-column-names --batch
-e "select table_name from tables where table_type = 'VIEW'
and table_schema = 'database'"
| xargs mysqldump -u username database
> views.sql
这将通过查询将所有视图名称提取到INFORMATION_SCHEMA数据库,然后将它们通过管道传递给xargs以制定mysqldump命令.需要--skip-column-names和--batch才能使输出xargs友好.如果您有很多视图,此命令行可能会变得太长,在这种情况下,您希望向选择项添加某种其他过滤器(例如,查找以给定字符开头的所有视图).
This extracts all of the view names via a query to the INFORMATION_SCHEMA database, then pipes them to xargs to formulate a mysqldump command. --skip-column-names and --batch are needed to make the output xargs friendly. This command line might get too long if you have a lot of views, in which case you'd want to add some sort of additional filter to the select (e.g. look for all views starting with a given character).
这篇关于使用Mysql Dump备份视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!