MySQL Export: One Table per File

Way to save a gzipped SQL dump of each table individually. Sometimes it’s useful to have separate table backups.

mysql -Nse 'select TABLE_SCHEMA, TABLE_NAME from TABLES' information_schema \
     | egrep -v 'information_schema|sys|mysql|performance_schema' \
     | awk '{print "mkdir -p "$1"; mysqldump -RQq "$1" "$2" \
     | gzip > "$1"/"$2".sql.gz"}' \
     | sh

The last part | sh executes each generated command.

Result

# ls -la 
drwxr-xr-x 30 root root 6144 Aug 19 16:57 .
drwxr-xr-x  3 root root 6144 Aug 19 16:54 ..
drwxr-xr-x  2 root root 6144 Aug 19 16:51 client0_celery
...
drwxr-xr-x  2 root root 6144 Aug 19 16:56 client132_celery

# ls -1 client0_celery
celery_taskmeta.sql.gz
django_migrations.sql.gz
...
djcelery_periodictask.sql.gz
djcelery_taskstate.sql.gz
Human Logic, AI Syntax... Note on Content: I'm a Systems Engineer, not a native English writer. To ensure my technical ideas are clear and accessible, I use AI tools to polish the grammar and style. The workflow is simple: I provide the logic, the code, and the real-world experience. The AI handles the "English-to-Human" translation layer. If you find a bug, that's on me. If you find a perfectly placed comma, that's probably the AI.

Comments

Popular posts from this blog

FreeRadius with Google Workspace LDAP

Fixing pssh (parallel-ssh) Problems on Debian 10 with Python 3.7