cPanel

How to Fix “Server sent charset (255) unknown to the client” in MySQL

Websites show “Server sent charset (255) unknown to the client” after moving to MySQL 8? Upgrade PHP, or set a utf8mb4 default in my.cnf for old PHP sites.

After moving a website to a server with MySQL 8, or after upgrading MySQL, the site may stop working with this error:

Server sent charset (255) unknown to the client. Please, report to the developers

The database itself is fine. The problem is that the website's PHP version is too old to understand MySQL 8's default settings. This guide explains why and gives two ways to fix it.

Quick answer

  • Best fix: switch the website to a current PHP version (8.2 or newer). In cPanel, use MultiPHP Manager (WHM) or Select PHP Version (cPanel).
  • If the site must stay on old PHP: set a different default character set in /etc/my.cnf and restart MySQL:
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

What you need: access to the site's PHP settings for the first fix, or root access to the server for the second.

Why it happens

Every connection between PHP and MySQL agrees on a character set (which letters and symbols can be stored) and a collation (how text is sorted and compared). MySQL 8 changed its default to utf8mb4 with a new collation, utf8mb4_0900_ai_ci, which has the ID number 255.

Old PHP versions were released before that collation existed. When MySQL announces "255", old PHP does not recognise it and refuses to connect. Newer PHP versions know it and connect normally. cPanel article PHP bug report

Moving the site to a current PHP version fixes the error, and is worth doing anyway: old PHP versions no longer get security updates.

In cPanel & WHM:

  • Server administrators: open WHM › Software › MultiPHP Manager, find the domain, and choose a newer PHP version.
  • cPanel users: open cPanel › Software › MultiPHP Manager (or Select PHP Version on CloudLinux servers) and choose a newer version.

Test the site afterwards. Very old websites or plugins may need updating to work on new PHP. If that is not possible straight away, use Fix 2 for now.

Fix 2: Change MySQL's default character set

If the website cannot move to a newer PHP version yet, make MySQL announce a collation that old PHP understands.

Back up the configuration file first:

cp /etc/my.cnf /etc/my.cnf.bak

Open /etc/my.cnf and add these two lines under the [mysqld] section (create the section if it does not exist):

[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

Then restart MySQL. On a cPanel server:

/scripts/restartsrv_mysql

Reload the website: it should connect normally.

utf8mb4 with utf8mb4_unicode_ci still supports every language and emoji, so your data is not affected. Avoid the older advice to set utf8 / utf8_unicode_ci here: in MySQL 8 that is an outdated 3-byte character set that cannot store emoji and some other characters.

This change applies to the whole server, and only to new connections and new tables. Existing tables keep their own settings.

If MySQL does not start after the change, restore the backup (cp /etc/my.cnf.bak /etc/my.cnf), restart MySQL and check the file for typing mistakes. See How to Fix the "mysql has failed" Error on a cPanel Server for reading the MySQL error log.

Which fix should I use?

Use Fix 1 whenever you can. Fix 2 keeps an old website working, but the old PHP version underneath it is the real problem, and it will cause other trouble later.

Sources

  1. cPanel: MySQL: Server sent charset (255) unknown to the client
  2. PHP bug #74461: mysqlnd and MySQL 8 default collation

Written by Tharanga. Commands and procedures depend on your system and software version.

How we approach technical guides →
FOLLOW THE THREAD

Keep exploring

All guides