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

时间:2019-07-30 07:46:29

标签: mysql docker-compose adminer

我正尝试使用来自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 个答案:

答案 0 :(得分:0)

您必须在撰写文件中添加默认的身份验证插件

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:

在管理员

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>