Mysql 5.7

docker mysql 官方文档

docker-compose.yml

  1. version: '3.1'
  2. services:
  3. mysql5.7:
  4. image: mysql:5.7.33
  5. command: --default-authentication-plugin=mysql_native_password
  6. restart: always
  7. environment:
  8. - TZ=Asia/Shanghai
  9. - MYSQL_ROOT_PASSWORD=root
  10. - MYSQL_DATABASE=初始数据库
  11. volumes:
  12. - ./mysql/mysql5.7/my.cnf:/etc/mysql/my.cnf
  13. - ./mysql/mysql5.7/data:/var/lib/mysql
  14. ports:
  15. - 3306:3306

下面简单说下重要参数作用:

  • MYSQL_DATABASE:初始化数据库,比如定义 demo,那么在容器启动后,会自动创建一个 demo 的数据库
  • TZ=Asia/Shanghai:控制该容器的时区

my.cnf 如果需要配置的话,可以使用如下的配置

  1. [client]
  2. default-character-set = utf8mb4
  3. [mysql]
  4. default-character-set = utf8mb4
  5. [mysqld]
  6. character-set-client-handshake = FALSE
  7. character-set-server = utf8mb4
  8. collation-server = utf8mb4_general_ci
  9. lower_case_table_names=1
  10. max_allowed_packet=32M
  11. max_connections=1024
  12. open_files_limit=65535
  13. tmp_table_size=124M
  14. interactive_timeout=300
  15. max_connect_errors=10000
  16. group_concat_max_len=2048
  17. thread_cache_size=20
  18. thread_stack=192K
  19. transaction-isolation = READ-COMMITTED
  20. key_buffer_size=128M
  21. read_buffer_size=8M
  22. read_rnd_buffer_size=16M
  23. join_buffer_size=16M
  24. sort_buffer_size=16M
  25. max_heap_table_size=123M

Mysql 8.0

Mysql 8.0 官方文档、docker mysql 官方文档

docker-compose.yml

  1. version: '3.1'
  2. services:
  3. mysql8_01:
  4. container_name: mysql8_01
  5. image: mysql:8.0
  6. command: --default-authentication-plugin=mysql_native_password
  7. restart: always
  8. environment:
  9. TZ: Asia/Shanghai
  10. MYSQL_ROOT_PASSWORD: root
  11. volumes:
  12. # - ./mysql8_01/my.cnf:/etc/mysql/my.cnf
  13. - ./mysql8_01/data:/var/lib/mysql
  14. ports:
  15. - 3306:3306
  1. 配置文件暂无。