MySQL and MariaDB
SafeGrd backs up MySQL 8.0 and 8.4 and MariaDB 10.6 and 11.4 with mysqldump. This page covers the grants the backup account needs, TLS options, restoring, and Amazon RDS and Aurora.
# MySQL 8.0 and 8.4, MariaDB 10.6 and 11.4 (each run by the test suite)
safegrd backup --database-url "mysql://backup:$DB_PASSWORD@db.internal:3306/shop" --retention-days 14
MySQL surfaces run mysqldump (or mariadb-dump) with
--single-transaction, which reads InnoDB tables from one consistent snapshot
without locking them. Backups include stored routines, triggers and events, with binary
columns written as hex. The output streams into the encrypted archive as it is produced.
Row counts are read from the dump stream itself, so they match the rows in the backup even
while the database is being written to.
- The host needs the MySQL client (
mysql-client, orbrew install mysql-clienton macOS). SafeGrd prefers the dump tool from the same project as the server, and MySQL's client has been tested against MariaDB 11.4 as well.SAFEGRD_MYSQLDUMPandSAFEGRD_MYSQLname them explicitly. - A backup account needs
SELECT,SHOW VIEW,TRIGGERandLOCK TABLESon the database. AddEVENTon it to back up scheduled events, andSHOW_ROUTINE ON *.*(MySQL 8.0.20 or newer) to back up stored procedures and functions other accounts created. Without them the backup runs, and says what it left out. - The password goes to the client in a private, owner-only options file that is deleted when the run ends, never on its command line.
- TLS:
?tls=trueencrypts and checks the server's certificate against the system's certificate authorities. MySQL's own certificate is self-signed and fails that check, so for a server that still uses it add?tls=skip-verify, which encrypts without checking, or?ssl-ca=/path/ca.pemto check it against your own CA.?tls=preferreduses TLS when the server offers it. A database SafeGrd backs up for you has no file forssl-cato name, so usetls=trueortls=skip-verifythere. ssl-mode, asmysqltakes it and as Aiven's URIs carry it, works in place oftls:REQUIREDistls=skip-verify,VERIFY_CAandVERIFY_IDENTITYaretls=true, andPREFERREDandDISABLEDaretls=preferredandtls=false. A URL that sets both, differently, is refused.- Restoring requires an empty target database and validates every table's restored row count against the snapshot manifest. Because MySQL applies DDL statements non-transactionally, a failed restore can leave partial schemas behind; drop and recreate the database before retrying.
- Database objects such as views, triggers, and stored routines preserve their original definer
accounts. Recreating an arbitrary definer requires
SET_USER_IDprivileges, which managed platforms like RDS do not grant. During restoration, SafeGrd rewrites object definers to match the restoring account and reports the number of modified definitions. - Rows up to the source server's
max_allowed_packetare backed up whole. Setmax_allowed_packeton the restore target at least as high as on the source. - Triggers created via multi-statement APIs may contain trailing semicolons that
mysqldumpexports in an invalid format. SafeGrd identifies affected triggers during backup, and sandbox drills will flag them since in-memory drills do not parse SQL syntax.
Amazon RDS and Aurora (MySQL)
Managed MySQL on RDS does not grant SUPER privileges, but SafeGrd does not need them.
- SafeGrd runs
mysqldumpwith--single-transactionand--set-gtid-purged=OFF, which works with standard user privileges. - During a restore, SafeGrd rewrites object definers (e.g.
%oradmin@%) to the restoring account so RDS does not reject them. - Backing up from an Aurora or RDS Read Replica keeps table scans off your write master.