d
Amit DhamuSoftware Engineer
 

Helpful mysqldump Commands

2 minute read 00000 views
# Dump a database
❯ mysqldump -u amit -p db1 > /tmp/db1.sql

# Dump multiple databases
❯ mysqldump -u amit -p --databases db1 db2 > /tmp/db1_db2.sql

# Dump all databases
❯ mysqldump -u amit -p --all-databases > /tmp/all_databases.sql

# Dump a table
❯ mysqldump -u amit -p db1 table1 > /tmp/db1.table1.sql

# Dump multiple tables
❯ mysqldump -u amit -p db1 table1 table2 > /tmp/db1.table1_table2.sql

# Dump structure only
❯ mysqldump -u amit -d -p db1 table1 > /tmp/db1_structure.sql

# Dump table data without create table syntax
❯ mysqldump -u amit -p --no-create-info db1 table1 > /tmp/db1.table1.sql

# Dump table data with query and without create table syntax
❯ mysqldump -u amit -p --no-create-info --where=gender='female' db1 table1 > /tmp/db1.table1.sql

# Dump with gzip
❯ mysqldump -u amit -p db1 table1 | gzip > /tmp/db1.table1.sql.gz

# Dump from remote database
❯ mysqldump -u amit -h 192.168.100.99 -p db1 table1 > /tmp/db1.table1.sql

# Restoring from a SQL file
❯ mysql -u amit -p db1 < /tmp/db1.table1.sql

# Restoring from gzip
❯ gunzip < /tmp/db1.table1.sql.gz | mysql -u amit -p db1

# Output a single table to CSV
❯ mysqldump -u amit -p -t --fields-terminated-by=, -T/tmp db1 table1