↑ ↓ select, Enter open, Esc close

Back up each database into its own gzipped file

Adjust the values, the command updates live
root@server
for db in $(mysql -NBe 'SHOW DATABASES' | grep -Ev '^(information_schema|performance_schema|sys)$'); do mysqldump --single-transaction --quick "$db" | gzip > "/root/db-backup/$db.sql.gz"; done

Queries the list of all databases, skips the internal system schemas and writes each database to its own .sql.gz file. This makes it possible to restore exactly one database later without digging through a huge combined dump. The target directory must exist beforehand.

Note: On Plesk servers, add -u admin to both calls and set MYSQL_PWD from /etc/psa/.psa.shadow.

Also searched as

  • backup each mysql database separately
  • mysql backup per database
  • export all databases to separate files

Related one-liners

All in MySQL and MariaDB

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.