diff --git a/CHANGELOG.md b/CHANGELOG.md index 40131267fac..1da10bbe6ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fixed a bug where accessing a custom field’s magic property on an element would return the field’s raw database value rather than `null`, if it didn’t belong to the element’s field layout anymore. ([#12539](https://github.com/craftcms/cms/issues/12539), [#12578](https://github.com/craftcms/cms/pull/12578)) - Fixed a bug where `craft\image\Raster::getIsTransparent()` wasn’t working. ([#12565](https://github.com/craftcms/cms/issues/12565)) - Fixed a bug where the component name comments in project config YAML files would always lag behind the current project config a little. ([#12576](https://github.com/craftcms/cms/issues/12576), ([#12581](https://github.com/craftcms/cms/pull/12581))) +- Fixed a MySQL error that occurred when creating a database backup using the default backup command, when running MySQL 5.7.41+ or 8.0.32+. ([#12557](https://github.com/craftcms/cms/issues/12557), [#12560](https://github.com/craftcms/cms/pull/12560)) - Added `craft\helpers\Db::escapeForLike()`. - `craft\services\Assets::getAllDescendantFolders()` now has a `$withParent` argument, which can be passed `false` to omit the parent folder from the results. ([#12536](https://github.com/craftcms/cms/issues/12536)) - Deprecated `craft\helpers\DateTimeHelper::timeZoneAbbreviation()`. diff --git a/src/db/mysql/Schema.php b/src/db/mysql/Schema.php index bd27956e5b0..35952414947 100644 --- a/src/db/mysql/Schema.php +++ b/src/db/mysql/Schema.php @@ -150,6 +150,18 @@ public function createColumnSchemaBuilder($type, $length = null) */ public function getDefaultBackupCommand(array $ignoreTables = null): string { + $useSingleTransaction = true; + $serverVersion = App::normalizeVersion(Craft::$app->getDb()->getSchema()->getServerVersion()); + + $isMySQL5 = version_compare($serverVersion, '8', '<'); + $isMySQL8 = version_compare($serverVersion, '8', '>='); + + // https://bugs.mysql.com/bug.php?id=109685 + if (($isMySQL5 && version_compare($serverVersion, '5.7.41', '>=')) || + ($isMySQL8 && version_compare($serverVersion, '8.0.32', '>='))) { + $useSingleTransaction = false; + } + $defaultArgs = ' --defaults-extra-file="' . $this->_createDumpConfigFile() . '"' . ' --add-drop-table' . @@ -163,8 +175,12 @@ public function getDefaultBackupCommand(array $ignoreTables = null): string ' --triggers' . ' --no-tablespaces'; + if ($useSingleTransaction) { + $defaultArgs .= ' --single-transaction'; + } + // If the server is MySQL 5.x, we need to see what version of mysqldump is installed (5.x or 8.x) - if (version_compare(App::normalizeVersion(Craft::$app->getDb()->getSchema()->getServerVersion()), "8", "<")) { + if ($isMySQL5) { // Find out if the db supports column-statistics $shellCommand = new ShellCommand(); @@ -198,7 +214,6 @@ public function getDefaultBackupCommand(array $ignoreTables = null): string $schemaDump = 'mysqldump' . $defaultArgs . - ' --single-transaction' . ' --no-data' . ' --result-file="{file}"' . ' {database}';