Home Blog Now

mysql-dump specific tables

2022-08-08 mysql database reference

If you only need to dump one table:

mysqldump -u username -ppassword db_name table_name > dump.sql

For multiple tables, separate the table names with a whitespace:

mysqldump -u username -ppassword db_name table_name_1 table_name_2 > dump.sql

To only get tables with a certain prefix, e.g pref_:

mysqldump db_name $(mysql -D db_name -Bse "show tables like 'pref\_%'") > dump.sql
# flags: -B batch, -s silent mode, -e execute

To only dump rows that meet a specific criteria:

mysqldump -u username -ppassword db_name table_name --where="where clause here" > dump.sql

Importing the dump file:

mysql -u username -ppassword db_name < dump.sql