The mysqldump
command in MySQL is used for creating backups of databases. Sometimes, you may need to exclude certain tables from being included in the backup. This can be achieved using the --ignore-table=name
option.
Ignoring Tables During mysqldump:
Let’s explore how to use the --ignore-table=name
option with mysqldump
through various examples:
-
Example 1: Ignore a Single Table
To ignore a specific table named
logs
during the backup:mysqldump --ignore-table=mydatabase.logs -u root -p mydatabase > backup.sql
This command excludes the
logs
table from the backup of themydatabase
database.Verification: After running the command, verify by checking the contents of
backup.sql
to ensure thelogs
table is not included. -
Example 2: Ignore Multiple Tables
If you need to ignore multiple tables, separate them with commas:
mysqldump --ignore-table=mydatabase.logs --ignore-table=mydatabase.temp_data -u root -p mydatabase > backup.sql
This excludes both the
logs
andtemp_data
tables from the backup.Verification: Check the contents of
backup.sql
to confirm the specified tables are excluded. -
Example 3: Ignore Tables Using Wildcards
Use wildcards to exclude tables based on a pattern:
mysqldump --ignore-table=mydatabase.prefix_* -u root -p mydatabase > backup.sql
This command ignores all tables in
mydatabase
that start withprefix_
.Verification: Check the backup file to ensure tables matching the wildcard pattern are excluded.
Also check similar articles.
Ignoring Errors During mysqldump
Connecting to MySQL Host in mysqldump
Dumping BLOBs in Hexadecimal Format with mysqldump
Forcing mysqldump Execution Even on Errors
Emitting FLUSH PRIVILEGES Statement in mysqldump
Discussion about this post