Dump each MySQL table to a file

Here’s a one-liner to dump each table in a database to it’s own .sql file. Crack open your shell of choice and follow along.

Replace the USER, PASSWORD, and DBNAME values with your own. If you’re not running this to connect to a local database, add –host=domain.tld after each password to connect to your remote server.

for i in $(mysql -uUSER -p'PASSWORD' --batch --skip-column-names DBNAME -e'show tables;'); do mysqldump -uUSER -p'PASSWORD' DBNAME $i > DBNAME-$i.sql; done

Users, passwords, and database names are case sensitive, I made them uppercase here to call them out.

This post originally featured on the EchoDitto Labs blog.