Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql dump - exclude some table data

Tags:

mysql

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 the structure of all 200 tables, but i want to ignore the data of 5 specific tables.

If this is possible, how is it done?

like image 626
Marty Wallace Avatar asked Nov 27 '12 21:11

Marty Wallace


People also ask

How do you ignore a table?

In order to tell mysqldump you want to exclude a single table, all you have to do is add the flag --ignore-table followed by the name of the table you want to exclude. After executing the command from the example above, the output file my_backup.

How do I dump a specific table?

mysqldump includes all the tables of the database by default. In order to dump only a specific set of tables using mysqldump , you need to specify the database name followed by the name of the tables you want to include in the dump. After running the command from the example above, the output file my_backup.

Is it possible to dump a table data in MySQL?

Under Export Options, select Export to Dump Project Folder if you want database tables to be stored to separate . sql files or Export to Self-Contained File to store the database dump in a single .

What is Mysqlcheck?

mysqlcheck uses the SQL statements CHECK TABLE , REPAIR TABLE , ANALYZE TABLE , and OPTIMIZE TABLE in a convenient way for the user. It determines which statements to use for the operation you want to perform, and then sends the statements to the server to be executed.


2 Answers

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 
like image 73
AmitP Avatar answered Oct 12 '22 22:10

AmitP


I think that AmitP's solution is great already - to improve it even further, I think it makes sense to create all tables (structure) first and then fill it with data, except the ones "excluded"

mysqldump --no-data db_name > export.sql mysqldump --no-create-info --ignore-table=db_name.table_name db_name >> export.sql 

if you want to exclude more than 1 table, simply use the --ignore-tabledirective more often (in the 2nc command) - see mysqldump help:

--ignore-table=name   Do not dump the specified table. To specify more than one                       table to ignore, use the directive multiple times, once                       for each table.  Each table must be specified with both                       database and table names, e.g.,                      --ignore-table=database.table 
like image 22
kantholy Avatar answered Oct 12 '22 22:10

kantholy