brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mysqldump --single-transaction takes a consistent database backup without locking

Database
~/tips/tip-database-mysqldump-single-transaction

mysqldump --single-transaction --routines --events mydb | gzip > mydb.sql.gz

Dumps a MySQL or MariaDB database from one consistent snapshot so applications can keep writing during the backup.

I like a dump that does not freeze my apps while it runs. With MySQL or MariaDB that is one flag away.

mysqldump --single-transaction --routines --events mydb | gzip > mydb.sql.gz

--single-transaction opens one repeatable-read transaction, so every InnoDB table is dumped as it looked at the start, and writers are not blocked. --routines and --events add stored procedures, functions and scheduled events, which a plain dump leaves out (triggers are already included by default).

The snapshot is only consistent for InnoDB. MyISAM tables are not covered, so a database that still has some of those needs --lock-tables or a short maintenance window.

Further reading: MySQL Reference Manual: mysqldump

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link