docker-compose:服务器请求的身份验证方法客户端未知

ssm49v7z  于 2021-06-21  发布在  Mysql
关注(0)|答案(3)|浏览(360)

我有一个yml文件用于在docker中配置mysql:


# 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

我使用以下命令从yml所在的同一目录启动容器:
docker compose-f stack.yml向上
然后我得到一个错误:

jhkqcmku

jhkqcmku1#

这对我有用:

image: mysql:5.7
wa7juj8i

wa7juj8i2#

因为我刚刚花了3个小时来寻找解决这个问题的方法,我想我应该扩展一下hatef的答案。添加命令 --default-authentication-plugin=mysql_native_password 但您必须首先运行以下一组命令:

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

这是因为在不清理容器(是的,标记为exited的容器)的情况下,并不是所有的卷都将被修剪。如果您不修剪所有的卷,db将从先前的示例中保留下来。这是令人困惑的,因为容器被认为是孤立的示例,但如果卷在它们之间持久存在,则不是这样。
请注意,这将解析phpmyadmin和任何其他基于php的mysql维护工具中的相同消息。
为了让事情更简单,我编写了一个powershell脚本来处理安装之间的进程/卷的清理。

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
oewdyzsn

oewdyzsn3#

如果您遇到这个错误,但仍然希望使用mysql v.8。您可以通过告诉mysql服务器使用遗留的身份验证插件来实现这一点。
因此,您的撰写文件将如下所示:


# 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

相关问题