【问题标题】:how to use custom.cnf in mysql server 8 docker-compose file?如何在 mysql server 8 docker-compose 文件中使用 custom.cnf?
【发布时间】:2021-07-02 04:04:23
【问题描述】:

尝试在 docker-compose mysql 8 中使用自定义配置文件。docker-compose.yml 看起来像

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

[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

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

我知道该命令可以在下面的 compose 文件中使用,但我想使用自定义文件

......
command: --character-set-server=utf8 --collation-server=utf8_bin --max-allowed-packet=32M --transaction-isolation=READ-COMMITTED
......

【问题讨论】:

    标签: mysql docker docker-compose mysql-8.0


    【解决方案1】:

    我尝试将image: mysql/mysql-server:8.0 替换为image: mysql:8.0 并且成功了。

    【讨论】:

      猜你喜欢
      • 2021-06-02
      • 2018-02-10
      • 2020-09-08
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 2019-05-31
      • 2020-11-21
      • 1970-01-01
      相关资源
      最近更新 更多