Docker构建:错误:ER_NOT_SUPPORTED_AUTH_MODE:MySQL客户端

问题描述 投票:2回答:2

当我尝试docker-compose -f docker-compose-now.yml up时收到此消息

error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

现在,我确实阅读了此解决方案:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

来自:https://github.com/mysqljs/mysql/issues/1507

但是如何将其放入docker-compose-now.yml中的entrypoints文件中?

我的环境在此文件中,并且当我尝试时:

entrypoints: sh "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root'"

我只收到另一个错误。

我该如何解决?

mysql docker docker-compose dockerfile
2个回答
2
投票

问题

为了清楚起见,您在入口点脚本中所做的实际上是在sh shell中执行的。您要运行的命令应在mysql shell中执行。

解决方案

您的入口点应该具有以下命令来运行mysql命令:

mysql -u root -p [root-password] -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"

如果您想在mysql数据库上执行此操作,则可以执行此操作

mysql -u root -p [root-password] mysql -e "update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';"

说明

[在此命令中,首先使用mysql -u -p命令进入mysql shell,然后使用-e标志执行sql命令(它代表execute)。在mysql shell中执行-e之后发生的一切(例如查询等)。有关详细信息和示例,请参考:

https://dev.mysql.com/doc/refman/8.0/en/command-line-options.html


0
投票
version: '3.1'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
© www.soinside.com 2019 - 2024. All rights reserved.