简体   繁体   English

如何备份表而不是视图

[英]how to backup the tables and not the views

Using mysqldump I can backup my database. 使用mysqldump可以备份数据库。 But my database has a lot of views with huge amount of data which I dont need. 但是我的数据库有很多不需要大量数据的视图。 I only want to backup the real tables with data. 我只想用数据备份实际表。

Currently I'm doing: 目前我正在做:

mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

Is there a way to backup only the real tables without the views? 有没有一种方法可以只备份没有视图的实际表?

Views don't store any data in MySQL. 视图在MySQL中不存储任何数据。 View are like stored queries, not stored data. 视图就像存储的查询,而不是存储的数据。 There is no content to the view, and it will not increase the size of your backup more than the size of the definition of the view. 该视图没有内容,它不会使备份的大小增加到超过视图定义的大小。 That is, the CREATE OR REPLACE VIEW statement is the only thing that ends up in your mysqldump output related to that view. 也就是说, CREATE OR REPLACE VIEW语句是与该视图相关的mysqldump输出中唯一的结果。

But to answer your question: no, there's no specific option to exclude all views. 但是要回答您的问题:不,没有特定的选项可以排除所有视图。

You can exclude individual names (whether they are tables or views) with the --ignore-table=db.table option. 您可以使用--ignore-table=db.table选项排除单个名称(无论它们是表还是视图)。 But you'd have to list every view individually. 但是您必须单独列出每个视图。

Another option is to mysqldump with a user who lacks the SHOW VIEW privilege. 另一个选择是与没有SHOW VIEW特权的用户一起使用mysqldump。 This will exclude views from the backup, but will generate an error. 这将从备份中排除视图,但会产生错误。 You can skip errors and continue the backup if you use the --force option. 如果使用--force选项,则可以跳过错误并继续备份。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM