无法使用Adminer和docker-compose连接MySQL数据库

4

我正在尝试使用docker hub上的官方adminermysql镜像连接我的mysql数据库。

这是我的docker-compose.yml文件配置:

version: '3'
services:
  mysql:
    image: mysql
    restart: always
    volumes: 
      - mysql:/var/lib/mysql
    environment: 
      - MYSQL_ALLOW_EMPTY_PASSWORD= 1
      - MYSQL_DATABASE= db
    ports: 
      - 3306:3306
      - 33060:33060
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on: 
      - mysql
volumes:
  mysql:

每当我想使用Adminer登录MySQL时,都会遇到以下问题:
SQLSTATE[HY000] [2054] 服务器请求的身份验证方法未知客户端
SQLSTATE[HY000] [2002] 没有这样的文件或目录
以下是我在尝试从Adminer界面连接到MySQL时使用的输入:
#first try
System: MySQL
Server: localhost
Username: root
Database: db

#second try
System: MySQL
Server: mysql #container-name
Username: root
Database: db
1个回答

10

您需要在compose文件中添加默认身份验证插件。

command: --default-authentication-plugin=mysql_native_password

以下是完整的docker-compose.yml文件

services:
  mysql:
    image: mysql
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    volumes: 
      - mysql:/var/lib/mysql
    environment: 
      - MYSQL_ALLOW_EMPTY_PASSWORD= 1
      - MYSQL_DATABASE= db
    ports: 
      - 3306:3306
      - 33060:33060
  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    depends_on: 
      - mysql
volumes:
  mysql:

在Adminer中:
System: MySQL <DB System to connect>
Server: mysql <should match the starting tag before image tag > (in your case mysql but you can change it to any name )
Username: root <username>
Password: <password>
Database: db <database name>

谢谢,我在使用Adminer时遇到了服务器字段的问题,我不知道我们需要指定docker-compose文件中的服务名称而不是容器的IP地址。 - damou_ 1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接