mysqldump
database management
exclude tables
SQL
data backup

mysqldump: exclude or skip specific tables with --ignore-table

Codemia Knowledge Hub ·


Use --ignore-table=database_name.table_name, and repeat the option once for every table you want to leave out. The database prefix is required on each one. People typically skip tables because of size, privacy, or because the tables are irrelevant to the snapshot.

Basic mysqldump usage

mysqldump exports a database as a logical backup (SQL) that you can import again with mysql or another tool that reads SQL files:

bash
mysqldump -u [username] -p [database_name] > [output_file].sql

This connects to the MySQL server as the given user and writes the chosen database to the output file. Everything below just adds options to this command.

Excluding one table

To skip table_to_skip in my_database:

bash
mysqldump -u [username] -p --ignore-table=my_database.table_to_skip my_database > my_database_dump.sql

Excluding several tables

There is no comma-separated form. Repeat --ignore-table for each table you want to skip:

bash
1mysqldump -u [username] -p \
2    --ignore-table=my_database.table1_to_skip \
3    --ignore-table=my_database.table2_to_skip \
4    my_database > my_database_dump.sql

A concrete case: business_db has orders, customers, archived_orders and logs, and you want a backup without logs and archived_orders:

bash
1mysqldump -u dba_user -p \
2    --ignore-table=business_db.logs \
3    --ignore-table=business_db.archived_orders \
4    business_db > business_db_partial_backup.sql

Option reference

OptionDescription
--ignore-table=db.tblExcludes the specified table from the dump. Specify full <database>.<table>.
-u [username]Connects to the MySQL server as the specified user.
-pPrompts for the password. Use it without password for security reasons.
[database_name]Specifies the database to be dumped.

Things to check when excluding tables

  1. Dependencies: skipping tables shrinks the dump and speeds it up, but dependencies between tables (such as foreign keys) are not handled for you.
  2. Quoting: quote or escape table names that contain special characters or spaces, or the shell will mangle them.
  3. Full backups: if your backup strategy needs complete snapshots, keep a separate routine that includes every table, especially for critical databases.
  4. Other options: --ignore-table combines with options such as --single-transaction for consistent dumps and --quick to avoid loading large tables into memory.
  5. Scripting: if you exclude tables regularly, generate the --ignore-table arguments in a shell script.
  6. Restore tests: test that the dump restores and that the missing tables do not break your data integrity checks.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design