magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Magento's `setup:db:status` fails with MySQL 8.0.29

Open lbajsarowicz opened this issue 2 years ago • 9 comments

Preconditions and environment

  • Magento 2.4.4
  • MySQL 8.0.29 and higher --- Server version: 8.0.29-0ubuntu0.20.04.3 (Ubuntu)

Steps to reproduce

  1. Set up Magento 2.4.4 following the requirements (https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html)
  2. Execute setup:upgrade
  3. Execute setup:db:status

Expected result

Magento should report that the Database is up-to-date

Actual result

  1. bin/magento setup:db:status

Declarative Schema is not up to date Run 'setup:upgrade' to update your DB schema and data.

  1. bin/magento setup:upgrade
  2. bin/magento setup:db:status

Declarative Schema is not up to date Run 'setup:upgrade' to update your DB schema and data.

  1. bin/magento setup:db-schema:upgrade
  2. bin/magento setup:db:status

Declarative Schema is not up to date Run 'setup:upgrade' to update your DB schema and data.

Additional information

Issue is caused by charset comparison.

Beginning with MySQL 8.0.28, utf8mb3 is also displayed in place of utf8 in columns of Information Schema tables, and in the output of SQL SHOW statements.

Prior to MySQL 8.0.29, instances of utf8mb3 in statements were converted to utf8. In MySQL 8.0.30 and later, the reverse is true, so that in statements such as SHOW CREATE TABLE or SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLUMNS or SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS, users see the character set or collation name prefixed with utf8mb3 or utf8mb3_.

image

The default table charset is defined in \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table::create image

Our internal workaround is a plugin which overrides default MySQL charset if no other provided:

<?php
declare(strict_types=1);

namespace SwiftOtter\MysqlCharsetFix\Plugin;

use Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table;

class OverrideDefaultCharsetPlugin
{
    private const DEFAULT_CHARSET = 'utf8mb3';

    /**
     * @param Table $subject
     * @param array $data
     * @return array
     */
    public function beforeCreate(Table $subject, array $data): array
    {
        if (!isset($data['charset'])) {
            $data['charset'] = self::DEFAULT_CHARSET;
        }

        return [$data];
    }
}

Another possible solution is to override \Magento\Framework\Setup\Declaration\Schema\Dto\Table::getDiffSensitiveParams parameters, excluding charset from the list. (Composer patch below)

diff --git a/Setup/Declaration/Schema/Dto/Table.php b/Setup/Declaration/Schema/Dto/Table.php
--- a/Setup/Declaration/Schema/Dto/Table.php
+++ b/Setup/Declaration/Schema/Dto/Table.php	(date 1655976014788)
@@ -343,7 +343,6 @@
             'resource' => $this->getResource(),
             'engine' => $this->getEngine(),
             'comment' => $this->getComment(),
-            'charset' => $this->getCharset(),
             'collation' => $this->getCollation()
         ];
     }

Huge thanks for helping with the investigation to @LeeSaferite, @navarr, and @so-max-u

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [X] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

lbajsarowicz avatar Jun 23 '22 23:06 lbajsarowicz

Hi @lbajsarowicz. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Jun 23 '22 23:06 m2-assistant[bot]

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Jun 24 '22 05:06 m2-assistant[bot]

Hi @lbajsarowicz , Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop branch with php 8.1 and the issue is reproducible. Hence confirming this issue. image

engcom-November avatar Jun 24 '22 05:06 engcom-November

This issue is reproducible in 2.4.3-p2. image

tgreeve avatar Jun 27 '22 08:06 tgreeve

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-5970 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Jul 15 '22 06:07 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Jul 15 '22 06:07 m2-assistant[bot]

The mentioned patch results (for me) in an error during setup:install

[Progress: 4 / 1998] Installing database schema: Schema creation/updates:

In ErrorHandler.php line 62:

Warning: Undefined array key "charset" in /var/www/html/vendor/magento/framework/Setup/Declaration/Schema/Db/MySQL/DbSchemaWriter.php on line 89

zapotocnylubos avatar Sep 18 '22 12:09 zapotocnylubos

@zapotocnylubos There are two possible patches - Just use the other one :)

lbajsarowicz avatar Sep 18 '22 12:09 lbajsarowicz

@lbajsarowicz U mean the plugin, right?

zapotocnylubos avatar Sep 18 '22 14:09 zapotocnylubos

Having the same issue, Creating a plugin <plugin name="fix_default_charset" type="Project\Theme\Plugin\OverrideDefaultCharsetPlugin" sortOrder="1"/> Does not fix this issue. After a successful deploy running setup:db:status still shows: Declarative Schema is not up to date

joachimVT avatar Oct 05 '22 12:10 joachimVT

I'm having the same issue. The schema is always not up to date. The \Magento\Framework\Setup\Declaration\Schema\Diff\Diff::$changes variable always has 400 entries and all of them are related to utf8mb3. Magento 2.4.5 PHP 8.1.13 MySQL version 8.0.30

speller avatar Dec 02 '22 03:12 speller

As a workaround, I'm using the following patch with the cweagans/composer-patches component:

--- a/Setup/Declaration/Schema/Dto/Factories/Table.php
+++ b/Setup/Declaration/Schema/Dto/Factories/Table.php
@@ -23,12 +23,12 @@
     /**
      * Default charset for SQL
      */
-    public const DEFAULT_CHARSET = 'utf8';
+    public const DEFAULT_CHARSET = 'utf8mb3';

     /**
      * Default collation
      */
-    public const DEFAULT_COLLATION = 'utf8_general_ci';
+    public const DEFAULT_COLLATION = 'utf8mb3_general_ci';

     /**
      * @var ObjectManagerInterface

It solves the problem with changes caused by encodings. I had other issues as well (#36558), so this workaround patch is not guaranteed to fix all issues.

speller avatar Dec 02 '22 07:12 speller

I think this means we need to update the charset in the database to utf8, since that's a reference at the moment for utf8mb3 and will be updated to a reference to utf8mb4. see: https://stackoverflow.com/a/52337457

same for utf8mb3_general_ci that needs to be updated to utf8_general_ci. Or am i wrong? @engcom-November

leonhelmus avatar Dec 07 '22 16:12 leonhelmus

Closed without an explanation telling why?

Possibly fixed by AC-7469: Add support for MySQL8.0.29 and higher ?

hostep avatar Jan 10 '23 21:01 hostep

@hostep; I guess some habits are hard to kick. 😉

nocturnalfrog avatar Jan 11 '23 08:01 nocturnalfrog

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-5970 by the internal team Related commits: https://github.com/magento/magento2/search?q=AC-7469&type=commits

Based on the Jira ticket, the target version is 2.4.6.

Thanks

engcom-Hotel avatar Jan 11 '23 09:01 engcom-Hotel

Hi all,

utf8mb3 character set is actually deprecated on MySQL 8, we should use utfmb4 instead.

https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html#:~:text=This%20character%20set%20is%20deprecated%20in%20MySQL%208.0%2C%20and%20you%20should%20use%20utfmb4%20instead

jonathanribas avatar Mar 21 '23 10:03 jonathanribas

@jonathanribas No disagreement - but Magento currently uses utf8mb3 and this issue is about fixing it not recognizing it.

A new issue should be created to move off the deprecated charset

navarr avatar Mar 21 '23 14:03 navarr

There is already one for utfmb4 support: https://github.com/magento/magento2/pull/35174

jonathanribas avatar Mar 22 '23 07:03 jonathanribas