Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#60002 new defect (bug)

maybe_convert_table_to_utf8mb4() not work with new version of MySQL/MariaDB.

Reported by: okvee's profile okvee Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

From [this document](https://mariadb.com/kb/en/unicode/). They said:
From MariaDB 10.6, utf8 is by default an alias for utf8mb3

And from [this document](https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html) in MySQL. They said:
Historically, MySQL has used utf8 as an alias for utf8mb3; beginning with MySQL 8.0.28, utf8mb3 is used exclusively in the output of SHOW statements and in Information Schema tables when this character set is meant.

It can be refer to [this issue](https://core.trac.wordpress.org/changeset/53918).

So, from this simple MySQL code:

CREATE TABLE testing (
    id bigint(20) NOT NULL AUTO_INCREMENT,
    name varchar(50) DEFAULT NULL,
    PRIMARY KEY (id)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1

If you run on MariaDB 10.6 or newer (for me it is 10.6.7) the utf8 column will be automatically changed to utf8mb3_general_ci.

But, WordPress function maybe_convert_table_to_utf8mb4() contain this condition:

<?php
if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
    // Don't upgrade tables that have non-utf8 columns.
    return false;
}

Which will be result in no change from utf8mb3_general_ci to utf8mb4_unicode_ci.

Change History (1)

#1 @ayeshrajans
3 months ago

Tested with MySQL 8.2, and SHOW FULL COLUMNS FROM $table indeed returns utf8mb3_... as the collation name. So I think you are right, that we need to change that line to something like this:

if ( 'utf8' !== $charset && 'utf8mb3' !== $charset && 'utf8mb4' !== $charset ) {
Note: See TracTickets for help on using tickets.