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 --routines --events keeps stored code in your backup

Backup
~/tips/tip-mysql-mysqldump-routines-events

mysqldump --routines --events mydb > mydb.sql

Adds stored procedures, functions and scheduled events to a mysqldump backup.

A dump that restores fine but is missing a stored procedure is the kind of surprise you only find on the day you need the backup. The fix is two flags that I would add to every dump command by default.

mysqldump --routines --events mydb > mydb.sql

The options are --routines (-R) for stored procedures and functions, and --events (-E) for scheduled events. Triggers have their own option, --triggers, and that one is on by default (you turn it off with --skip-triggers).

As far as I know, routines and events are not part of a dump unless you ask for them, so a plain mysqldump mydb restores your tables and triggers but quietly leaves the procedures and events behind. Check the full mysqldump page for your version before you rely on the default.

It works with the other selection options too, for example --all-databases:

mysqldump --all-databases --routines --events > all.sql

One caveat: the account running the dump needs enough privileges to read those definitions, and the dump is only as complete as that account’s view. The manual lists SELECT for tables, SHOW VIEW for views and TRIGGER for triggers. After a restore on a new server, also check that the definer accounts of the routines exist, because routines keep their original definer. MariaDB’s mariadb-dump has the same two options.

Further reading: MySQL mysqldump

More Backup tips restic snapshots --group-by host,paths rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats tmutil verifychecksums /path/to/backup-item All Backup tips (45) All topics

Link