Skip to content
Advertisement

PHP-mysqli can’t connect to MySQL 8.0.16 running in a Docker

Summary:

  • mysql-server 8.0.16 is running inside a Docker container.
  • php 7 + Apache2 + myslnd 5.0.12 + mysqld 5.6.22 are running outside Docker.

In PHP, mysqli fails thus:

JavaScript

Meanwhile mysql can connect thus from outside Docker:

JavaScript

Question: How can I get mysqli_connect working?

Details:

Here are some of the relevant GRANT entries.

JavaScript

I found the /etc/my.cnf inside the docker image and enabled

JavaScript

That allowed even an old (5.6) mysql to connect thus:

JavaScript

And, yes, it came back with a heading including

JavaScript

It seems that the commandline mysql knows about mysql_native_password, but mysqlnd does not.

More version info:

JavaScript

phpinfo says this about mysqlnd:

JavaScript

#docker ps (shows port mapping):

JavaScript

PHP-CLI also fails to connect.

(Yes, I ran FLUSH PRIVILEGES; at the appropriate time.)

Advertisement

Answer

You’ve tried setting default-authentication-plugin in my.cnf – perhaps try to do it as a command arg instead? I had similar problems trying to auth, but this works for me in my docker-compose.yml – I never tried setting it in my.cnf

JavaScript

(command taken from the Docker docs page for MySQL).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement