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

混江龙づ霸主 提交于 2020-01-10 18:46:05

问题


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

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

services:

  db:
    image: mysql
    restart: always
    environment:
       MYSQL_ROOT_PASSWORD: 'pass'
       MYSQL_DATABASE: 'db'
       MYSQL_USER: 'user'
       MYSQL_PASSWORD: 'pass'

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8080

And I start the container using following command from the same directory where yml is located:

docker-compose -f stack.yml up

Then I got this error:


回答1:


This worked for me:

image: mysql:5.7



回答2:


If you encounter this error but still wish to use MySQL v.8. You can do this by telling MySQL Server to use the legacy authentication plugin.

So, your compose file will look like this:

# Use root/example as user/password credentials

version: '3.1'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
       MYSQL_ROOT_PASSWORD: 'pass'
       MYSQL_DATABASE: 'db'
       MYSQL_USER: 'user'
       MYSQL_PASSWORD: 'pass'

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8080



回答3:


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


来源:https://stackoverflow.com/questions/50097032/docker-compose-the-server-requested-authentication-method-unknown-to-the-clien

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!