Some charset change in MariaDB 11.3.1 appears to break PHP clients, raising the error 'Server sent charset (0) unknown to the client'.
I noticed /etc/mysql/mariadb.conf.d/50-server.cnf changed
collation-server = utf8mb4_general_ci (11.2.2)
to
character-set-collations = utf8mb4=uca1400_ai_ci (11.3.1)
If I change this back, connections from PHP work again.
This Plesk user seems to have encountered the same issue: https://talk.plesk.com/threads/500-plesk-exception-database-db-query-failed-sqlstate-hy000-2054-server-sent-charset-0-unknown-to-the-client.372563/
Steps to reproduce:
- Install PHP 8.3, including MySQLi extension.
- Install MariaDB 11.3.1, CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';.
- Test a PHP page, e.g.
|
<?php
|
error_reporting(E_ALL);
|
ini_set('display_errors', 'on');
|
$conn = new mysqli("localhost", "username", "password");
|
if ($conn->connect_error) {
|
die("Connection failed: " . $conn->connect_error);
|
}
|
echo "Connected successfully";
|
?>
|
- Observe error:
Fatal error: Uncaught mysqli_sql_exception: Server sent charset (0) unknown to the client. Please, report to the developers in /var/www/html/index.php:4 Stack trace: #0 /var/www/html/index.php(4): mysqli->__construct() #1 {main} thrown in /var/www/html/index.php on line 4
|
{"report":{"fcp":1598.5,"ttfb":620.4000000953674,"pageVisibility":"visible","entityId":126845,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"260d383e-8f52-4b32-81da-68c7bd540c45","navigationType":0,"readyForUser":1676.5999999046326,"redirectCount":0,"resourceLoadedEnd":1860.9000000953674,"resourceLoadedStart":628.0999999046326,"resourceTiming":[{"duration":356.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":628.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":628.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":984.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":356.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":628.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":628.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":985,"responseStart":0,"secureConnectionStart":0},{"duration":420.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":628.5999999046326,"connectEnd":628.5999999046326,"connectStart":628.5999999046326,"domainLookupEnd":628.5999999046326,"domainLookupStart":628.5999999046326,"fetchStart":628.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":628.5999999046326,"responseEnd":1049.0999999046326,"responseStart":1049.0999999046326,"secureConnectionStart":628.5999999046326},{"duration":488.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":628.7999997138977,"connectEnd":628.7999997138977,"connectStart":628.7999997138977,"domainLookupEnd":628.7999997138977,"domainLookupStart":628.7999997138977,"fetchStart":628.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":628.7999997138977,"responseEnd":1117.4000000953674,"responseStart":1117.4000000953674,"secureConnectionStart":628.7999997138977},{"duration":494.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":629,"connectEnd":629,"connectStart":629,"domainLookupEnd":629,"domainLookupStart":629,"fetchStart":629,"redirectEnd":0,"redirectStart":0,"requestStart":629,"responseEnd":1123.4000000953674,"responseStart":1123.4000000953674,"secureConnectionStart":629},{"duration":497.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":629.1999998092651,"connectEnd":629.1999998092651,"connectStart":629.1999998092651,"domainLookupEnd":629.1999998092651,"domainLookupStart":629.1999998092651,"fetchStart":629.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":629.1999998092651,"responseEnd":1126.5,"responseStart":1126.5,"secureConnectionStart":629.1999998092651},{"duration":498.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":629.2999997138977,"connectEnd":629.2999997138977,"connectStart":629.2999997138977,"domainLookupEnd":629.2999997138977,"domainLookupStart":629.2999997138977,"fetchStart":629.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":629.2999997138977,"responseEnd":1128,"responseStart":1128,"secureConnectionStart":629.2999997138977},{"duration":574.2999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":629.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":629.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1203.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":498.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":629.5999999046326,"connectEnd":629.5999999046326,"connectStart":629.5999999046326,"domainLookupEnd":629.5999999046326,"domainLookupStart":629.5999999046326,"fetchStart":629.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":629.5999999046326,"responseEnd":1128.5,"responseStart":1128.5,"secureConnectionStart":629.5999999046326},{"duration":574.3000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":629.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":629.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1204,"responseStart":0,"secureConnectionStart":0},{"duration":499.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":629.9000000953674,"connectEnd":629.9000000953674,"connectStart":629.9000000953674,"domainLookupEnd":629.9000000953674,"domainLookupStart":629.9000000953674,"fetchStart":629.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":629.9000000953674,"responseEnd":1129.1999998092651,"responseStart":1129.1999998092651,"secureConnectionStart":629.9000000953674},{"duration":758.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":633.5,"connectEnd":633.5,"connectStart":633.5,"domainLookupEnd":633.5,"domainLookupStart":633.5,"fetchStart":633.5,"redirectEnd":0,"redirectStart":0,"requestStart":633.5,"responseEnd":1391.9000000953674,"responseStart":1391.9000000953674,"secureConnectionStart":633.5},{"duration":1217.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":642.4000000953674,"connectEnd":642.4000000953674,"connectStart":642.4000000953674,"domainLookupEnd":642.4000000953674,"domainLookupStart":642.4000000953674,"fetchStart":642.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":642.4000000953674,"responseEnd":1859.5,"responseStart":1859.5,"secureConnectionStart":642.4000000953674},{"duration":175.7000002861023,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1216.7999997138977,"connectEnd":1216.7999997138977,"connectStart":1216.7999997138977,"domainLookupEnd":1216.7999997138977,"domainLookupStart":1216.7999997138977,"fetchStart":1216.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":1216.7999997138977,"responseEnd":1392.5,"responseStart":1392.5,"secureConnectionStart":1216.7999997138977},{"duration":347.2000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1513.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1513.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1860.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":446.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1515.0999999046326,"connectEnd":1515.0999999046326,"connectStart":1515.0999999046326,"domainLookupEnd":1515.0999999046326,"domainLookupStart":1515.0999999046326,"fetchStart":1515.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1515.0999999046326,"responseEnd":1961.6999998092651,"responseStart":1961.6999998092651,"secureConnectionStart":1515.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":431,"responseStart":620,"responseEnd":632,"domLoading":625,"domInteractive":1910,"domContentLoadedEventStart":1910,"domContentLoadedEventEnd":1974,"domComplete":2739,"loadEventStart":2739,"loadEventEnd":2740,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1865.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1866.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1866.7999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":1872.2999997138977},{"name":"activityTabFullyLoaded","time":2001}],"measures":[],"correlationId":"59b72db7e5af45","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":128,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
it's coming from https://github.com/php/php-src/blob/642e11140c3a8461ab9a78d6ce3d3a79b0151987/ext/mysqlnd/mysqlnd_commands.c#L619
and the reason is that the server sends 0 in the server default collation byte of the initial handshake packet for collations that are above 1..255 range.
But actually the connector is mainly interested in the character set, not the collation. We could try to "gracefully downgrade" the collation and if it's above 255, return another collation of the same character set but with a smaller id.