Database: Handle the utf8mb3 charset reported by newer MySQL and MariaDB versions - #13456
Database: Handle the utf8mb3 charset reported by newer MySQL and MariaDB versions#13456faisalahammad wants to merge 1 commit into
Conversation
…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.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
MySQL 8.0.30+ and MariaDB 10.6.1+ report the
utf8charset asutf8mb3inSHOWstatements and Information Schema output. Some code that inspects that output still only checks forutf8andutf8mb4, so tables can end up unconverted or collations invalid on those servers. 5d78ecbe25 already fixed this insidewpdbfor table charset lookups and text checks. This PR fixes the remaining two gaps:maybe_convert_table_to_utf8mb4()Before:
src/wp-admin/includes/upgrade.phplisted each column charset withif ( 'utf8' !== $charset && 'utf8mb4' !== $charset ). On MySQL 8.0.30+ or MariaDB 10.6.1+, every column of autf8table is reported asutf8mb3, so the check failed and the function returnedfalse. Tables were left unconverted during upgrades.After:
utf8mb3is accepted in the allowlist, matching theutf8andutf8mb4entries already handled byget_table_charset().wpdb::determine_charset()Before:
src/wp-includes/class-wpdb.phponly matched an exact'utf8'charset, and rewrote collations withstr_replace( 'utf8_', 'utf8mb4_', ... ). On newer servers,'utf8mb3'fell through untouched, and a reported collation likeutf8mb3_general_ciwould pair with the upgraded charset to produce the invalid combinationutf8mb4+utf8mb3_general_ci, causing "illegal mix of collations" errors.After:
utf8mb3is treated likeutf8and normalized toutf8mb4,utf8mb3_general_ciis treated likeutf8_general_ci, andutf8mb3_collation prefixes are rewritten alongsideutf8_. This matches the existing handling inget_table_charset()andcheck_safe_collation().Testing
New tests:
Tests_DB::test_utf8mb3_charset_switched_to_utf8mb4()andTests_DB::test_utf8mb3_non_unicode_collation_switched_to_utf8mb4()fordetermine_charset().Tests_Admin_IncludesUpgrade::test_maybe_convert_table_to_utf8mb4_converts_utf8_table()and::test_maybe_convert_table_to_utf8mb4_skips_non_utf8_columns()formaybe_convert_table_to_utf8mb4(). The tests use a real table and remove thequeryfilters that rewriteCREATE TABLEtoCREATE TEMPORARY TABLE, becauseSHOW TABLE STATUScannot see temporary tables. On servers that still reportutf8, the create usesutf8, 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.