MySQL 8.0: Prepare your (really) old Wordpress
... / MySQL 8.0: Prepare your (...
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Question

MySQL 8.0: Prepare your (really) old Wordpress

by
MikaelD1
Newbie
Created on 2024-04-25 19:37:06 (edited on 2024-09-04 14:07:14) in Hébergement Web-old

Post en français ici.

TL;DR: To avoid accent issues after the MySQL 5.7 to 8.0 upgrade, check that DB_CHARSET is set in your Wordpress' wp-config.php.

----------

Brace yourself, MySQL 8.0 is coming soon on the databases delivered with your web hostings, also called "SharedSQL" (more info soon). Waiting for that, I have several topics for you, and this is the first one. It's about the Wordpress sites created before 2007 (more precisely: Wordpress sites created before Wordpress 2.2, released in 2007).

Warning, if your web site had been created with a Wordpress before 2.2, then upgraded, then you may be impacted, even if you use the last Wordpress version. Explanations and easy solution, let's go! 😃


**Technical context**

First of all, a little bit of context. I love to know where we come from. This helps to know where we're going 🙂

2001, Michael Widenius co-funded MySQL. Michael is from Finland. So he choosed the latin1 / swedish as the default character set / collation of MySQL (Finnish uses an alphabet derived from the Swedish one).

At that time, that was OK, as Michael had no idea his DBMS will be one of the most massively used in the world years later.

But it quickly became a problem, as the Swedish alphabet is not the most popular or relevant one to use all over the world. And that's a big problem, as moving from a character set / collation to another one is a real pain.

Proof: 22 years later, latin1 / swedish were still the default character set / collation in MySQL 5.7!

Since MySQL 8.0, the default character set is UTF-8 (called "utf8mb4" by MySQL).


**Wordpress default charset**

By default, Wordpress uses the character set defined on wp-config.php:

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

This parameter is UTF-8 by default, and exists since Wordpress 2.2, released 17 years ago, in 2007.

If this parameter is not set (what is the case of Wordpress created before September 2007), then Wordpress uses the database default character set.

As MySQL 8.0 changes the default character set from latin1 to utf8mb4, Wordpress that do not have this parameter (so, they're using latin1) will encounter accent issues (for instance, a "é" seen as "é"). Indeed, the data is encoded using latin1 in the database (that stays as-is), but they will be seen as UTF-8.


**Impact**

If you have:

1. A Wordpress
2. AND content on your database using latin1 (with means your database had been created with a Wordpress before 2007)
3. AND you didn't specified DB_CHARSET

Then, your website will have charset issues.


**Solution**

The solution is easy, and you can set it up right now:

* If you have a DB_CHARSET in your wp-config.php, keep it as-is, whatever its value.
* If you do not have any DB_CHARSET in your wp-config.php, then add this to your file, now:

define( 'DB_CHARSET', 'latin1' );

Mikaël