magento2: Magento's `setup:db:status` fails with MySQL 8.0.29
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
- Set up Magento 2.4.4 following the requirements (https://devdocs.magento.com/guides/v2.4/install-gde/system-requirements.html)
- Execute
setup:upgrade
- Execute
setup:db:status
Expected result
Magento should report that the Database is up-to-date
Actual result
bin/magento setup:db:status
Declarative Schema is not up to date Run ‘setup:upgrade’ to update your DB schema and data.
bin/magento setup:upgrade
bin/magento setup:db:status
Declarative Schema is not up to date Run ‘setup:upgrade’ to update your DB schema and data.
bin/magento setup:db-schema:upgrade
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_.
The default table charset is defined in \Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Table::create
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.
- 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”.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 19 (4 by maintainers)
Commits related to this issue
- Fix for setup:db:status in 2.4.4 Fix for setup:db:status in 2.4.4 based on https://github.com/magento/magento2/issues/35671 — committed to magemojo/m2-patches by nemke82 2 years ago
- Update 2-4-4-db-status-fix.patch https://github.com/magento/magento2/issues/35671 — committed to magemojo/m2-patches by nemke82 2 years ago
Hi all,
utf8mb3
character set is actually deprecated on MySQL 8, we should useutfmb4
instead.https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-sets.html#:~:text=This character set is deprecated in MySQL 8.0%2C and you should use utfmb4 instead
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.