Is it possible, using mysql dump to export the entire database structure, but exclude certain tables data from export.
Say the database has 200 tables, I wish to export
This will produce export.sql with structure from all tables and data from all tables excluding table_name
mysqldump --ignore-table=db_name.table_name db_name > export.sql
mysqldump --no-data db_name table_name >> export.sql
Previous answers don't fix the issue with the AUTO_INCREMENT
when we export the structure and don't show how to export some specific data in tables.
To go further, we must do :
1/ Export the structure
mysqldump --no-data db_name | sed 's/ AUTO_INCREMENT=[0-9]*\b//g' > export-structure.sql
2/ Export only data and ignores some tables
mysqldump --no-create-info --ignore-table=db_name.table_name1 [--ignore-table=db_name.table_name2, ...] db_name >> export-data.sql
3/ Export specific data in one table
mysqldump --no-create-info --tables table_name --where="id not in ('1', '2', ...)" > export-table_name-data.sql
I tried to use the --skip-opt
option to reset AUTO_INCREMENT
but this also delete the AUTO_INCREMENT
definition on the field, the CHARSET
and other things