Skip to content

fix(dbserver): add --single-transaction and MySQL 9.5+ dump flags to export-db - #8797

Merged
rfay merged 1 commit into
ddev:mainfrom
rfay:20260902_rfay_mysql_97_export
Sep 12, 2026
Merged

rfay merged 1 commit into
ddev:mainfrom
rfay:20260902_rfay_mysql_97_export

Conversation

@rfay

@rfay rfay commented Sep 2, 2026

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

ddev export-db now passes --single-transaction on every MySQL/MariaDB version for a consistent non-locking dump, and on MySQL 9.5+ (currently mysql:9.7) also passes --set-gtid-purged=OFF and --no-tablespaces so the export stays clean of GTID metadata and tablespace-privilege errors that MySQL 9.5+'s new defaults introduce.

The Issue

MySQL 9.5 changed the default of gtid_mode to ON. Since export-db dumps a single project database (not --all-databases, and not for replication), mysqldump's default --set-gtid-purged=AUTO behavior on a GTID-enabled server produced this on every export:

Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
Warning: A dump from a server that has GTIDs enabled will by default include the GTIDs of all transactions, even those that were executed during its extraction and might not be represented in the dumped data. This might result in an inconsistent data dump.
In order to ensure a consistent backup of the database, pass --single-transaction or --lock-all-tables or --source-data.

The dump still worked and re-imported fine with import-db, so this wasn't a functional bug, but it was alarming noise on every export-db run against MySQL 9.7. Separately, mysqldump's CREATE TABLESPACE statements need the PROCESS privilege, which the dumping user in a containerized MySQL setup typically doesn't have.

How This PR Solves The Issue

GetDBDumpCommand() in pkg/ddevapp/ddevapp.go now builds the dump command with flags instead of returning a bare binary name:

  • --single-transaction is added unconditionally, for all MySQL and MariaDB versions, closing the second warning above and giving a consistent InnoDB snapshot without locking tables.
  • --set-gtid-purged=OFF and --no-tablespaces are added only when the database is MySQL and the detected version is >= 9.5, using the existing util.SemverValidate helper rather than hardcoding 9.7, so this keeps working automatically if DDEV adds a newer 9.x version later.

--routines/--triggers/--events are unchanged; --triggers was already mysqldump's default, and --routines/--events were never included in export-db's single-database dumps at any version, so that's out of scope here.

Manual Testing Instructions

  1. On a project configured with mysql:9.7, run ddev export-db -f dump.sql.gz and confirm the GTID/single-transaction warnings above no longer appear.
  2. Confirm the export still imports cleanly: ddev import-db -f dump.sql.gz.
  3. Repeat on a project using an older MySQL (e.g. mysql:8.0) and on MariaDB, and confirm --set-gtid-purged/--no-tablespaces are not added (no behavior change there beyond the new --single-transaction).

Automated Testing Overview

Added TestGetDBDumpCommand in pkg/ddevapp/ddevapp_test.go, a unit test covering the flag set chosen for MySQL 8.0/8.4/9.4 (no gated flags), MySQL 9.5/9.7 (gated flags present), and MariaDB below/at/above the existing 10.5 mariadb-dump cutover.

Release/Deployment Notes

export-db output changes for every user: the GTID/tablespace warnings on MySQL 9.5+ disappear, and --single-transaction is now always used. No config or CLI flag changes; no impact on import-db.

@rfay
rfay requested a review from a team as a code owner September 2, 2026 20:42
@github-actions github-actions Bot added the bugfix label Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8797

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

…export-db

MySQL 9.5+ defaults gtid_mode to ON, which makes mysqldump emit
GTID_PURGED warnings/statements on export-db's single-database dumps,
and dumping users in containerized MySQL typically lack the PROCESS
privilege CREATE TABLESPACE statements require.

GetDBDumpCommand() now always adds --single-transaction for a
consistent non-locking snapshot, and adds --set-gtid-purged=OFF and
--no-tablespaces only when the detected MySQL version is >=9.5, gated
on the version number so it keeps working for future 9.x releases.
@rfay
rfay force-pushed the 20260902_rfay_mysql_97_export branch from 2adf1b8 to c9a2b22 Compare September 11, 2026 19:04
@rfay
rfay merged commit accbe7f into ddev:main Sep 12, 2026
47 of 48 checks passed
@rfay
rfay deleted the 20260902_rfay_mysql_97_export branch September 12, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants