Skip to content

Instantly share code, notes, and snippets.

@cagartner
Last active September 9, 2021 17:14
Show Gist options
  • Save cagartner/7fad60e25b0a403c6a179bab4b8e5994 to your computer and use it in GitHub Desktop.
Save cagartner/7fad60e25b0a403c6a179bab4b8e5994 to your computer and use it in GitHub Desktop.
Patch for fix Magento 2.4.3 and Mysql 8.0+, this error happens during the reindex process and happens because they can't create the temporary table.

Step 1

Install the composer patch modules:

composer require cweagans/composer-patches

Step 2

Copy the patch file content/name and add to your root magento in patchs/composer/mysql-temporary-tables-fix.patch

Step 3

Add the following code to your composer.json file:

"extra": {
    "magento-force": "override",
    // Lines added here:
    "composer-exit-on-patch-failure": true,
    "patches": {
        "magento/framework": {
            "Mysql 8 Temporary table fix": "patches/composer/mysql-temporary-tables-fix.patch"
        }
    }
}

Step 4

Run composer update --lock to update your composer and install the patch.

Index: vendor/magento/framework/DB/Adapter/Pdo/Mysql.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php b/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php
--- a/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php
+++ b/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php (date 1631205570843)
@@ -2228,7 +2228,11 @@
$ifNotExistsSql = ($ifNotExists ? 'IF NOT EXISTS' : '');
$temporaryTable = $this->quoteIdentifier($this->_getTableName($temporaryTableName));
$originTable = $this->quoteIdentifier($this->_getTableName($originTableName));
- $sql = sprintf('CREATE TEMPORARY TABLE %s %s LIKE %s', $ifNotExistsSql, $temporaryTable, $originTable);
+ if (version_compare($this->getServerVersion(), '8.0.0', '<')) {
+ $sql = sprintf('CREATE TEMPORARY TABLE %s %s LIKE %s', $ifNotExistsSql, $temporaryTable, $originTable);
+ } else {
+ $sql = sprintf('CREATE TEMPORARY TABLE %s %s SELECT * FROM %s', $ifNotExistsSql, $temporaryTable, $originTable);
+ }
return $this->query($sql);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment