繁体   English   中英

PHP-mysqli 无法连接到在 Docker 中运行的 MySQL 8.0.16

[英]PHP-mysqli can't connect to MySQL 8.0.16 running in a Docker

概括:

  • mysql-server 8.0.16在 Docker 容器内运行。
  • php 7 + Apache2 + myslnd 5.0.12 + mysqld 5.6.22Docker之外运行。

在 PHP 中,mysqli 因此失败:

mysqli_connect('127.0.0.1', 'test', 'test', 'test', 8016)

ERR: 2054 : The server requested authentication method unknown to the client

同时mysql可以从外部Docker 连接:

mysql  -P 8016 -h 127.0.0.1 -u test -ptest test

问题:如何让mysqli_connect工作?

细节:

以下是一些相关的 GRANT 条目。

mysql> select host, user, db, select_priv, grant_priv
                  from mysql.db where user='test';
+------------+------+------+-------------+------------+
| host       | user | db   | select_priv | grant_priv |
+------------+------+------+-------------+------------+
| 172.17.0.1 | test | test | Y           | N          |

mysql> select host, user, plugin, select_priv, grant_priv
                    from mysql.user where user='test';
+------------+------+-----------------------+-------------+------------+
| host       | user | plugin                | select_priv | grant_priv |
+------------+------+-----------------------+-------------+------------+
| 172.17.0.1 | test | mysql_native_password | N           | N          |

我发现泊坞窗图像的/etc/my.cnf并启用

default-authentication-plugin=mysql_native_password

这甚至允许旧的 (5.6) mysql连接:

mysql  -P 8016 -h 127.0.0.1 -u test -ptest test

而且,是的,它返回的标题包括

Server version: 8.0.16 MySQL Community Server - GPL

似乎命令行mysql知道mysql_native_password ,但mysqlnd不知道。

更多版本信息:

PHP Version 7.0.33-0ubuntu0.16.04.6
Apache/2.4.18 (Ubuntu) 

phpinfo关于mysqlnd是这样说的:

Version:         mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $
Loaded plugins:  mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
API Extensions:  mysqli,pdo_mysql 

#docker ps (显示端口映射):

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                  PORTS                               NAMES
99193bedb36c        mysql/mysql-server:8.0.16   "/entrypoint.sh my..."   8 weeks ago         Up 12 hours (healthy)   33060/tcp, 0.0.0.0:8016->3306/tcp   o8016

PHP-CLI 也无法连接。

(是的,我在适当的时间运行了FLUSH PRIVILEGES; 。)

您已经尝试在my.cnf设置default-authentication-plugin - 也许尝试将其作为command arg 来代替? 我在尝试身份验证时遇到了类似的问题,但这在我docker-compose.yml对我docker-compose.yml - 我从未尝试在my.cnf设置它

mysql:
    container_name: myapp-db
    image: mysql:8.0
    command: --default-authentication-plugin=mysql_native_password
    environment:
     (snip)

command取自 MySQL 的 Docker 文档页面)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM