docker-compose 启动utf-8 mysql

docker-compose 启动utf-8 mysql

  • docker-compose 启动中文 utf-8 mysql
    • 中文 utf-8支持
    • 启动
    • 停止
    • 示例

docker-compose 启动中文 utf-8 mysql

中文 utf-8支持

全局默认字符集修改
command:
- mysqld
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci

参考:mysql dockerfile
https://hub.docker.com/layers/mysql/library/mysql/5.7/images/sha256-9f768489d306402ea11243f1b96aeaa4696adb9ed7c1bb0318724759b9cbd1a6?context=explore

端口映射
ports:
- “3307:3306”

默认密码
environment:
- MYSQL_ROOT_PASSWORD=passw0rd

启动

docker-compose -f mysql.yml up -d

停止

docker-compose -f mysql.yml down

示例

# this is incompatible with sql_mode=only_full_group_by
select @@GLOBAL.sql_mode;

cat config/custom.cnf 

[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
cat mysql-stable.yaml 

version: '3'

services:
  mysql1:
    container_name: mysql01
    hostname: mysql01
    image: "mysql:5.7"
    restart: always
    ports:
      - "3311:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=passw0rd
      - MYSQL_ROOT_HOST='%'
      - MYSQL_DATABASE=portal
      - TZ=Asia/Shanghai
    command:
      - mysqld
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
     #- --default-time-zone=+8:00
    volumes:
      - /data/docker/mysql/data1:/var/lib/mysql
      - /data/docker/mysql/config/custom.cnf:/etc/mysql/conf.d/custom.cnf
      - ./init:/docker-entrypoint-initdb.d/
  mysql7:
    container_name: mysql07
    hostname: mysql07
    image: "mysql:5.7"
    restart: always
    ports:
      - "3312:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=passw0rd
      - MYSQL_ROOT_HOST='%'
      - TZ=Asia/Shanghai
    command:
      - mysqld
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      #- --default-time-zone=+8:00
    volumes:
      - /data/docker/mysql/data7:/var/lib/mysql
      - /data/docker/mysql/config/custom.cnf:/etc/mysql/conf.d/custom.cnf
      

你可能感兴趣的:(mysql,docker,mysql,docker-compose,utf-8,中文)