Error: Server sent charset (255) unknown to the client

The full error is:

PHP Warning: mysql_connect(): Server sent charset (255) unknown to the client. Please, report to the developers in…

This is attempting to connect to MySQL 8 on Digital Ocean from a PHP 5.4 container. Now, I’m not sure if this is fixable, how it is fixable, and whether it si worth fixing.

From my research, the problem is not PHP, but the MySQL Connector library that does not support the default MySQL characterset of utf8mb4. It does not matter what characterset the database is, as this is about the connection and does not get as far as the database.

Restrictions I have are:

  • I am stuck on PHP 5.4 for this app. Legacy, bah.
  • I cannot change the default client characterset on the database (it is managed, and client settings afre locked).

I suspect the only solution from the container side would be to compile a patched version of the MySQL connector. My immediate solution is to run my own MySQL database, rather than the managed one, where I can make changes to the settings.

However, I’m raising this here in case anyone in this community has already got a solution I can try.

Here is evidence that PHP is already set up to use uitg8mb4: php-src/mysqlnd_charset.c at PHP-5.4.45 · php/php-src · GitHub

Here is a SO answer that nicely sums up what I think is happening here: php - PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers - Stack Overflow

My legacy app is using mysql_connect(), but mysqli and PDO both do the same thing, since they are all wrappers for the same MySQL connector.