docker-compose : The server requested authentication method unknown to the client

前端 未结 3 1423
春和景丽
春和景丽 2020-12-30 06:21

I have this yml file for configuration of MySQL in docker:

# Use root/example as user/password credentials
version: \'3.1\'

services:

  db:
    image: mysq         


        
3条回答
  •  生来不讨喜
    2020-12-30 06:51

    Since I just spent the last 3 hours looking for a solution for this same issue, I thought I'd extend on Hatef's answer. Adding the command --default-authentication-plugin=mysql_native_password to the container works but you have to first run the following set of commands:

    docker rm $(docker ps -a -q)
    docker volume prune -f
    

    This is because without cleaning up the containers (yes, the ones marked exited), not all of the volumes will be pruned. And if you don't prune all of the volumes, the db will persist from the prior instance. This was confusing because containers are thought of as isolated instances, but not if the volumes are persisting between them.

    Note that this resolves the same message in phpmyadmin and any other php-based mysql maintenance tool.


    To make things easier, I wrote a powershell script that handles cleaning up the process/volumes between installations.

    Write-Host 'Begin configuring MySQL Server'
    $server = @{
        name = 'testdb';
        mysql_database = 'test';
        mysql_user = 'test';
        mysql_pass = '';
        mysql_root_pass = '';
        mysql_port = '3306';
        mysql_version = 'latest';
        adminer_port = '8080';
        adminer_version = 'latest';
    };
    $stackFilePath = '.\stack.yml';
    if (Test-Path $stackFilePath)
    {
        Write-Host 'Cleaning up old configuration file'
        Remove-Item $stackFilePath
    }
    $stack = @"
    version: '3.7'
    services:
      mysql:
        image: mysql:$($server.mysql_version)
        container_name: $($server.name)-mysql
        command: --default-authentication-plugin=mysql_native_password
        environment:
          - MYSQL_ROOT_PASSWORD=$($server.mysql_root_pass)
          - MYSQL_DATABASE=$($server.mysql_database)
          - MYSQL_USER=$($server.mysql_user)
          - MYSQL_PASSWORD=$($server.mysql_pass)
          - MYSQL_PORT=$($server.mysql_port)
          - MYSQL_ALLOW_EMPTY_PASSWORD=true
        restart: always
        ports:
          - $($server.mysql_port):$($server.mysql_port)
        expose:
          - $($server.mysql_port)
      adminer:
        image: adminer:$($server.adminer_version)
        container_name: $($server.name)-adminer
        depends_on:
          - mysql
        restart: always
        ports:
          - $($server.adminer_port):8080
    "@;
    Write-Host 'Writing new configuration file'
    $stack | Out-File -FilePath $stackFilePath
    
    Write-Host 'Clean up old processes'
    docker rm $(docker ps -a -q)
    
    Write-Host 'Clean up old volumes'
    docker volume prune -f
    
    Write-Host 'Create service from configurations'
    docker-compose -f $stackFilePath up
    

提交回复
热议问题