Skip to content

Database: Handle the utf8mb3 charset reported by newer MySQL and MariaDB versions - #13456

Open
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/60002-utf8mb3-charset
Open

Database: Handle the utf8mb3 charset reported by newer MySQL and MariaDB versions#13456
faisalahammad wants to merge 1 commit into
WordPress:trunkfrom
faisalahammad:ticket/60002-utf8mb3-charset

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Sep 9, 2026

Copy link
Copy Markdown

MySQL 8.0.30+ and MariaDB 10.6.1+ report the utf8 charset as utf8mb3 in SHOW statements and Information Schema output. Some code that inspects that output still only checks for utf8 and utf8mb4, so tables can end up unconverted or collations invalid on those servers. 5d78ecbe25 already fixed this inside wpdb for table charset lookups and text checks. This PR fixes the remaining two gaps:

maybe_convert_table_to_utf8mb4()

Before: src/wp-admin/includes/upgrade.php listed each column charset with if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ). On MySQL 8.0.30+ or MariaDB 10.6.1+, every column of a utf8 table is reported as utf8mb3, so the check failed and the function returned false. Tables were left unconverted during upgrades.

After: utf8mb3 is accepted in the allowlist, matching the utf8 and utf8mb4 entries already handled by get_table_charset().

wpdb::determine_charset()

Before: src/wp-includes/class-wpdb.php only matched an exact 'utf8' charset, and rewrote collations with str_replace( 'utf8_', 'utf8mb4_', ... ). On newer servers, 'utf8mb3' fell through untouched, and a reported collation like utf8mb3_general_ci would pair with the upgraded charset to produce the invalid combination utf8mb4 + utf8mb3_general_ci, causing "illegal mix of collations" errors.

After: utf8mb3 is treated like utf8 and normalized to utf8mb4, utf8mb3_general_ci is treated like utf8_general_ci, and utf8mb3_ collation prefixes are rewritten alongside utf8_. This matches the existing handling in get_table_charset() and check_safe_collation().

Testing

New tests:

  • Tests_DB::test_utf8mb3_charset_switched_to_utf8mb4() and Tests_DB::test_utf8mb3_non_unicode_collation_switched_to_utf8mb4() for determine_charset().
  • Tests_Admin_IncludesUpgrade::test_maybe_convert_table_to_utf8mb4_converts_utf8_table() and ::test_maybe_convert_table_to_utf8mb4_skips_non_utf8_columns() for maybe_convert_table_to_utf8mb4(). The tests use a real table and remove the query filters that rewrite CREATE TABLE to CREATE TEMPORARY TABLE, because SHOW TABLE STATUS cannot see temporary tables. On servers that still report utf8, the create uses utf8, so the tests pass on older setups too.

Verified that the new tests fail against unpatched trunk and pass with the fix. Focused suites pass on MySQL 9.7 (Tests_Admin_IncludesUpgrade, Tests_DB, Tests_DB_Charset, Tests_DB_dbDelta, IncludesSchema): 105 tests, 212 assertions. PHPCS clean on the touched files.

Trac ticket: https://core.trac.wordpress.org/ticket/60002

Use of AI Tools

AI assistance: Yes
Tool(s): ZCode
Model(s): GLM 5.3 flash
Used for: Ticket research, implementing the charset checks, writing the regression tests, and running the local test suite. The changes and this description were reviewed and submitted by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…aDB versions.

MySQL 8.0.30+ and MariaDB 10.6.1+ report the utf8 charset as utf8mb3 in
SHOW statements and Information Schema output.

Accept utf8mb3 in the column charset allowlist in
maybe_convert_table_to_utf8mb4(), and treat utf8mb3 like utf8 in
wpdb::determine_charset() so the collation is upgraded along with the
charset.

See #60002.
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant