Wordpress: Docker Image Fails To Work With Latest MySQL8 Docker Image

Created on 22 Jul 2018  路  6Comments  路  Source: docker-library/wordpress

Tried using wordpress with mysql:latest docker image. I get the following error trying to connect to the DB:

Warning: mysqli_real_connect(): Unexpected server respose while doing caching_sha2 auth: 109 in /var/www/html/wp-includes/wp-db.php on line 1531

Warning: mysqli_real_connect(): MySQL server has gone away in /var/www/html/wp-includes/wp-db.php on line 1531

Warning: mysqli_real_connect(): (HY000/2006): MySQL server has gone away in /var/www/html/wp-includes/wp-db.php on line 1531

It would appear the mysql plugin is too old to support authenticating with the latest version of mysql? I had to bump down the auth to the old 5.x methodology to get this to work.

Excerpt from phpinfo();

mysqlnd

mysqlnd => enabled
Version => mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $

It seems pretty old to me?

Request question

Most helpful comment

Interesting that the error message contains a typo ("respose" instead of "response"). This made me assume that the error was from my code instead of from MySQL or the MySQL plugin directly.

All 6 comments

According to docs: http://php.net/manual/en/ref.pdo-mysql.php

MySQL 8

When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server's default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used.

This is because MySQL 8 defaults to caching_sha2_password, a plugin that is not recognized by the older PHP (mysqlnd) releases. Instead, change it by setting default_authentication_plugin=mysql_native_password in my.cnf. The caching_sha2_password plugin will be supported in a future PHP release. In the meantime, the mysql_xdevapi extension does support it.

PHP Version on the image should support it?

$ php --version
PHP 7.2.8 (cli) (built: Jul 21 2018 07:52:06) ( NTS )

It would appear the mysql plugin is too old to support authenticating with the latest version of mysql?

Right, you can use an older version if you want the default_authentication_plugin by default, or set it as such in mysql through the my.cnf
If you want your supported version of PHP to use sha_2 then PHP mentions this plugin provides that.

Given that PHP says the sha2 authentication method will be supported in a future release, we don't necessarily try to provide features or functionality that upstream doesn't.

7.2.8 > 7.2.4, shouldn't version 7.2.8 be a version that works with mysql8?

If by "works with mysql8" you mean "supports sha2 by default" then no, it needs an extension for that as they state on the webpage you linked

The caching_sha2_password plugin will be supported in a future PHP release.
In the meantime, the mysql_xdevapi extension does support it.

Here are some resources I found talking about php and mysql 8:
https://stackoverflow.com/questions/49083573/php-7-2-2-mysql-8-0-pdo-gives-authentication-method-unknown-to-the-client-ca
https://github.com/phpmyadmin/phpmyadmin/issues/14220
https://github.com/laradock/laradock/issues/1392

Seems that PHP just fixed default authentication for MYSQL8 https://github.com/php/php-src/commit/d6e81f0bfd0cb90586dd83d4fd47a4302605261a
it doesn't show up in the changelog

Heres the bug report for it https://bugs.php.net/bug.php?id=76243

Going to close since this seems resolved and is also upstream's domain

Interesting that the error message contains a typo ("respose" instead of "response"). This made me assume that the error was from my code instead of from MySQL or the MySQL plugin directly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TeachMeHowToUse2FA picture TeachMeHowToUse2FA  路  4Comments

harobed picture harobed  路  5Comments

etc0de picture etc0de  路  4Comments

shankie-codes picture shankie-codes  路  5Comments

andheiberg picture andheiberg  路  5Comments