我想使用 docker 镜像启动 MySQL 本地实例。
到目前为止,我的 docker-compose.yml
文件如下所示:
version: '3.3'
services:
db:
image: mysql:8
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql-dump:/docker-entrypoint-initdb.d
restart: always
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: sqlPractice
MYSQL_USER: admin
MYSQL_PASSWORD: admin
ports:
- '7142:3306'
security_opt:
- seccomp:unconfined
到目前为止,一切正常。我的数据库提供了数据,但在执行一次查询后,如:
SELECT DISTINCT surname, name, data FROM exams e JOIN students s ON e.`id-student` = s.`id-student` WHERE passed='Y' AND (data, `id-centre`) = (SELECT MIN(data), e.`id-centre` FROM exams e JOIN centers c ON e.`id-center` = c.`id-center` WHERE e.passed='Y' AND c.`center-name` = 'IT Institute')
我收到如下错误:
ER_MIX_OF_GROUP_FUNC_AND_FIELDS: In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'sqlPractice.e.id-center'; this is incompatible with sql_mode=only_full_group_by
根据这篇文章:
click
我想在我的 docker-compose.yml
中设置一个参数 sql_mode
因为据称这会解决一个问题。
我的 docker-compose.yml
在命令标志中有两个参数看起来像:
version: '3.3'
services:
db:
image: mysql:8
command:
- default-authentication-plugin=mysql_native_password
- sql_mode=""
volumes:
- ./mysql-dump:/docker-entrypoint-initdb.d
restart: always
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_DATABASE: sqlPractice
MYSQL_USER: admin
MYSQL_PASSWORD: admin
ports:
- '7142:3306'
security_opt:
- seccomp:unconfined
但毕竟我在启动时收到错误
db_1 | /usr/local/bin/docker-entrypoint.sh: line 363: exec: default-authentication-plugin=mysql_native_password: not found
毕竟容器不能正常工作。
我想要实现的是通过 docker-compose.yml
配置 MySQL 实例,这两个参数在 command
param in docker-compose.yml
使我的查询按预期工作。
对于如何实现目标的建议,我将不胜感激。
最佳答案
services:
db:
image: mysql:8
command: ['--sql_mode=', '--default-authentication-plugin=mysql_native_password']
关于mysql - 如何在 docker-compose.yml 中使用多行命令标志配置 MySQL 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58535964/