David LeBauer
David LeBauer

Reputation: 31741

Is it possible to dump and import views using mysqldump?

When I use mysqldump and the re-import the dump, the views become empty tables.

Is it possible to either

a) dump and then import views without turning them into empty tables?

or, if a is not possible,

b) exclude views from mysqldump with a wildcard, such as

mysqldump mydb  --ignore-table=*views > mydb.sql

to exclude all views, if all views have names ending with the string "views"? (this part has been previously asked but remains unanswered: Ignore 'views' in mysql db backup using mysqldump)

Upvotes: 3

Views: 3876

Answers (1)

Michael Durrant
Michael Durrant

Reputation: 96484

Use --compact --add-drop-table and then manually adjust the dump file.

Details:

--compact

Produce more compact output. This option enables the --skip-add-drop-table, --skip-add-locks, --skip-comments, --skip-disable-keys, and --skip-set-charset options.
Note:

Prior to MySQL 5.1.21, this option did not create valid SQL if the database dump contained views. The recreation of views requires the creation and removal of temporary tables and this option suppressed the removal of those temporary tables. As a workaround, use --compact with the --add-drop-table option and then manually adjust the dump file.

Upvotes: 1

Related Questions