I installed a new instance of PHPMyAdmin to work with MySQL8. When accessing the main page I receive an alert with the message:
Notice in ./libraries/classes/Charsets.php#154
Undefined index: utf8mb3
Backtrace
./libraries/classes/Controllers/HomeController.php#163: PhpMyAdminCharsets::getServerCharset(,
boolean false,)
./libraries/classes/Routing.php#186: PhpMyAdminControllersHomeController->index(array)
./index.php#18: PhpMyAdminRouting::callControllerForRoute(
string '/',,,)
My MySQL server and client encoding is: utf8.
Any idea how I can fix it?
2
Answers
Cause
This seems to be caused by a bug in MySQL 8 when setting
character_set_server
toutf8
in the MySQL ([mysqld]
) config.The MySQL manual states:
However, the query
SHOW VARIABLES LIKE 'character_set_server';
still returns->
utf8mb3
The relevant part of the code in phpMyAdmin can be found in
libraries/classes/Charsets.php
:What phpMyAdmin is doing in the method
getServerCharset
inlibraries/classes/Charsets.php
(which is causing the error) is the following:It checks whether it has already determined the charset. If not,
it loads an array of charsets available from the MySQL server with the method
loadCharsets
. This however is done either by the querySHOW CHARACTER SET;
or by queryinginformation_schema
. In both cases,utf8
(instead ofutf8mb3
) is returned, as explained above in the MySQL manual.Then, it gets the server charset with the query
SHOW VARIABLES LIKE 'character_set_server';
(Here,utf8mb3
is returned as the result, as seen above).There is a fallback (not relevant in our case) due to a bug in MySQL 5.7.8, which we can ignore.
It writes the result into the variable
self::$serverCharset
, by getting the array element with the key$serverCharset
(which isutf8mb3
) from the array of all server charsets available . As we know, there is no keyutf8mb3
in the array of the available server charsets (onlyutf8
which is the alias forutf8mb3
). Therefore, the error occurs.How to fix it
To fix this, either MySQL should instead return
utf8
on the querySHOW VARIABLES LIKE 'character_set_server';
, which isn’t something we can easily influence (a bug report might have to be created), or we have to work around it in the phpMyAdmin source code.To do this, I added
before the line
so that it now looks like this:
The error should not occur anymore.
We are looking for you, please in future report this issues to our GitHub tracker
See: issue #16931
Here is the official fix: a2855079abccc05940286424d3017bf8ca9b3c7d
Solution: install phpMyAdmin 5.1.1 or newer