docker-compose:mariadb - 连接被拒绝

步骤1)mysql5 &phpmyadmin

镜像下面的mysql-phpmyadmin配置:

版本:'3.6'服务:D b:图片:mysql:5.7.24# 图片:mysql:8.0.18# 图片:mariadb:10.4.8# 命令:--default-authentication-plugin=mysql_native_password重启:总是卷:- ./mysql5:/var/lib/mysql# - ./mysql8:/var/lib/mysql# - ./mariadb:/var/lib/mysql环境:- MYSQL_ROOT_PASSWORD=测试- MYSQL_DATABASE=测试- MYSQL_USER=测试- MYSQL_PASSWORD=测试phpmyadmin:图片:phpmyadmin/phpmyadmin:4.8.5重启:总是依赖于取决于:- D b环境:- PMA_HOST=db- PMA_PORT=3306- PMA_USER=测试- PMA_PASSWORD=测试端口:- 3333:80"

我可以通过 phpmyadmin 访问我的 mysql 数据库:

按照 docker hub 上的 mariadb-README,环境配置应与对于 mysql5 容器.我假设,我还需要启用 mysql_native_password,它对 mysql8-container 不起作用.

我错过了什么?这是一个错误还是我错过了什么?

解决方案

它适用于 mariadb--default-authentication-plugin=mysql_native_password,只是容器启动真的很慢.

这是一个 MWE,它适用于不同的 mysql 版本(5 和 8)和最新的 mariadb(10):

  • https://github.com/boldt/docker-compose-mariadb-mysql-phpmyadmin

Step 1) mysql5 & phpmyadmin

Image the following mysql-phpmyadmin configuration:

version: '3.6'

services:

  db:
    image: mysql:5.7.24
#    image: mysql:8.0.18
#    image: mariadb:10.4.8
#    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
    - ./mysql5:/var/lib/mysql
#    - ./mysql8:/var/lib/mysql
#    - ./mariadb:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=test
    - MYSQL_DATABASE=test
    - MYSQL_USER=test
    - MYSQL_PASSWORD=test

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:4.8.5
    restart: always
    depends_on:
    - db
    environment:
    - PMA_HOST=db
    - PMA_PORT=3306
    - PMA_USER=test
    - PMA_PASSWORD=test
    ports:
    - "3333:80"

I can access my mysql-database via phpmyadmin: http://localhost:3333/

Step 2) mysql8 & phpmyadmin

Now I switch to mysql8, where I only the image and volume and added the command-option with the mysql_native_password-plugin:

version: '3.6'

services:

  db:
#    image: mysql:5.7.24
    image: mysql:8.0.18
#    image: mariadb:10.4.8
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
#    - ./mysql5:/var/lib/mysql
    - ./mysql8:/var/lib/mysql
#    - ./mariadb:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=test
    - MYSQL_DATABASE=test
    - MYSQL_USER=test
    - MYSQL_PASSWORD=test

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:4.8.5
    restart: always
    depends_on:
    - db
    environment:
    - PMA_HOST=db
    - PMA_PORT=3306
    - PMA_USER=test
    - PMA_PASSWORD=test
    ports:
    - "3333:80"

I can access my mysql-database via phpmyadmin: http://localhost:3333/

Step 3) mariadb & phpmyadmin

Now I switch to mariadb with the following configuration, where I only changed the image and volume:

version: '3.6'

services:

  db:
#    image: mysql:5.7.24
#    image: mysql:8.0.18
    image: mariadb:10.4.8
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
#    - ./mysql5:/var/lib/mysql
#    - ./mysql8:/var/lib/mysql
    - ./mariadb:/var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=test
    - MYSQL_DATABASE=test
    - MYSQL_USER=test
    - MYSQL_PASSWORD=test

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:4.8.5
    restart: always
    depends_on:
    - db
    environment:
    - PMA_HOST=db
    - PMA_PORT=3306
    - PMA_USER=test
    - PMA_PASSWORD=test
    ports:
    - "3333:80"

Now I cannot access my mariadb-database via phpmyadmin:

Following the mariadb-README on docker hub, the environment configuration should be the same as for the mysql5-container. I assume, that I also need to enable the mysql_native_password, which does not work as for the mysql8-container.

What do I miss? Is this a bug or do I miss something?

解决方案

It works for mariadb with --default-authentication-plugin=mysql_native_password, just the container start is really slow.

[Edit] Here is a MWE, which works with different mysql-versions (5 and 8) and the newest mariadb (10):

  • https://github.com/boldt/docker-compose-mariadb-mysql-phpmyadmin

相关文章