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

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

This worked for me:

image: mysql:5.7

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