From 02a21bc60448481efb3bd50d57426f0e399014f9 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Sun, 22 Jan 2023 20:00:47 -0800 Subject: [PATCH 1/4] Fix for #12557 --- src/db/mysql/Schema.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/db/mysql/Schema.php b/src/db/mysql/Schema.php index bd27956e5b0..02c7c29966a 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}'; From fa7bc7f6e39d8ed64ba689a42127be506c169b17 Mon Sep 17 00:00:00 2001 From: Brad Bell Date: Sun, 22 Jan 2023 20:01:50 -0800 Subject: [PATCH 2/4] space --- src/db/mysql/Schema.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/mysql/Schema.php b/src/db/mysql/Schema.php index 02c7c29966a..0ac91d15aa0 100644 --- a/src/db/mysql/Schema.php +++ b/src/db/mysql/Schema.php @@ -156,7 +156,7 @@ public function getDefaultBackupCommand(array $ignoreTables = null): string $isMySQL5 = version_compare($serverVersion, "8", "<"); $isMySQL8 = version_compare($serverVersion, "8", ">="); - //https://bugs.mysql.com/bug.php?id=109685 + // 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; From 0b22be9587dd291c36ca979743847315ab9d75c0 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 2 Feb 2023 16:59:35 -0800 Subject: [PATCH 3/4] Cleanup --- src/db/mysql/Schema.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/db/mysql/Schema.php b/src/db/mysql/Schema.php index 0ac91d15aa0..35952414947 100644 --- a/src/db/mysql/Schema.php +++ b/src/db/mysql/Schema.php @@ -153,12 +153,12 @@ 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", ">="); + $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", ">="))) { + if (($isMySQL5 && version_compare($serverVersion, '5.7.41', '>=')) || + ($isMySQL8 && version_compare($serverVersion, '8.0.32', '>='))) { $useSingleTransaction = false; } From f549d7ea64d363c24ccfcd20338774f9e3eb3c7a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 2 Feb 2023 17:01:33 -0800 Subject: [PATCH 4/4] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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()`.