14

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:

then i get following error while logging in

hatef
  • 4,383
  • 28
  • 42
  • 43
Navin Gelot
  • 1,142
  • 3
  • 11
  • 29

4 Answers4

23

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
hatef
  • 4,383
  • 28
  • 42
  • 43
  • 5
    @slayerbleast you'll have to reinitialize the database – Nathan Osman Jul 11 '19 at 03:58
  • 3
    @NathanOsman is right you gotta remove that container, remove the volumes if you have any and then build it up again. Then it will work. Just tried that and it worked for me. – Robert Aug 13 '19 at 21:07
7

This worked for me:

image: mysql:5.7
trozen
  • 889
  • 10
  • 12
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
Ethan DeLong
  • 162
  • 2
  • 11
0

You can just add this line after the image and it will start working again.

command: --default-authentication-plugin=mysql_native_password
jerryurenaa
  • 2,644
  • 15
  • 15