首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在mysql server 8 docker-compose文件中使用custom.cnf?

如何在mysql server 8 docker-compose文件中使用custom.cnf?
EN

Stack Overflow用户
提问于 2021-04-06 19:09:27
回答 1查看 195关注 0票数 0

尝试在docker-compose MySQL8中使用自定义配置文件。

代码语言:javascript
复制
version: '3'
services:
  db:
    container_name: test-mysql8
    image: mysql/mysql-server:8.0
    volumes:
      - <host path to>/mycustom.cnf:/etc/mysql/conf.d/custom.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=pass
      - MYSQL_DATABASE=testdb
      - MYSQL_USER=testuser
      - MYSQL_PASSWORD=testpassword
    ports:
      - "3306:3306"
    restart: always

  adminer:
    image: adminer:latest
    restart: always
    ports:
      - "8080:8080"

下面是自定义配置文件mycustom.cnf

代码语言:javascript
复制
[mysqld]
max_allowed_packet=32M
character-set-server=utf8
collation-server=utf8_bin
transaction_isolation=READ-COMMITTED

运行docker-compose up -d并验证变量docker exec -it test-mysql8 bash

代码语言:javascript
复制
mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%max_allowed_packet';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| max_allowed_packet        | 67108864   |
| mysqlx_max_allowed_packet | 67108864   |
| slave_max_allowed_packet  | 1073741824 |
+---------------------------+------------+
3 rows in set (0.00 sec)

应将mycustom.cnf中给定的变量值作为max_allowed_packet=33554432而不是max_allowed_packet=67108864

我知道该命令可以在合成文件中使用,如下所示,但我想使用自定义文件

代码语言:javascript
复制
......
command: --character-set-server=utf8 --collation-server=utf8_bin --max-allowed-packet=32M --transaction-isolation=READ-COMMITTED
......
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-09 18:18:09

我试着用image: mysql:8.0替换image: mysql/mysql-server:8.0,并且成功了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66967501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档