I know this is an old question but this week we had to migrate an old PHP 5.3 + Apache web server tools to docker containers and been forced to used php:5.6-apache.
We couldn't change the MySQLs remote servers configs since we are not the owners.
We didn't have any issue with PHP 5.3 to connect on MySQL 8+ servers so I compared both configs and php_info() outputs and realized that PHP 5.4+ is now using 'mysqlnd' as a built-in default driver (native) to connect to MySQL databases using mysql or mysqli extensions. It seems that the 'mysqlnd' provided with PHP 5.6 was the problem.
The way we fixed it was by installing the mysql-client and default-libmysqlclient-dev packages in our images that is basically the MariaDb's driver that IS able to connect to MySQL 8+ and did configure PHP to use it instead of native mysqlnd one.
In the Dockerfile, we first installed:
RUN apt update -y \
&& DEBIAN_FRONTEND=noninteractive apt install -y \
mysql-client \
default-libmysqlclient-dev
Then with php:5.6-apache image's built-in docker-php-ext-* scripts:
RUN docker-php-ext-configure mysql --with-mysql=/usr/ \
&& docker-php-ext-install mysql \
&& docker-php-ext-configure mysqli --with-mysqli=/usr/bin/mysql_config \
&& docker-php-ext-install mysqli
I hope this will help the community.
Thanks.