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

5 mysql docker dockerfile docker-compose

当我尝试时,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
Run Code Online (Sandbox Code Playgroud)

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

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
Run Code Online (Sandbox Code Playgroud)

来自: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'"
Run Code Online (Sandbox Code Playgroud)

我只收到另一个错误。

请问我该如何解决?

Nik*_*eke 5

version: '3'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWOR=example
Run Code Online (Sandbox Code Playgroud)

我在 mysql 镜像中的 Docker hub 上找到了解决方案。它为 docker-compose.yml 设置了更改身份验证模式的“命令”。

  • 提供代码而不提供解释并不是一个好的答案。编辑您的答案,以便每个人都能理解所提供的解决方案是什么。 (4认同)

Saq*_*med 4

问题

从长远来看,您在入口点脚本中所做的事情实际上是在 shell 中执行的sh。您要运行的命令应在mysqlshell 内执行。

解决方案

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

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

如果你想在mysql数据库上执行此操作,你可以这样做

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

解释

在这个命令中,首先使用命令进入mysql shell ,然后使用flag(它代表执行)mysql -u -p执行sql命令。-e之后发生的任何事情都-e在 mysql shell 中执行(如查询等)。有关详细信息和示例,请参阅此:

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