3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Docker + MySQL 文字化け対策

Posted at

はじめに

Docker + MySQLで文字化けが発生した際に色々とハマってしまったのでメモとして残しておく。

ディレクトリ構成

docker_mysql
  ├──docker-compose.yml
  ├──mysql
  │    ├──data #永続化用のマウント先
  │    ├──init.sql #初期データ投入SQL
  │    ├──my.cnf #my.cnf

docker-compose.yml / my.cnf

docker-compose.yml
version: '3'

services:
  mysql:
    image: mysql:8.0
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --skip-character-set-client-handshake
    volumes:
      - ./mysql/data:/var/lib/mysql
      - ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
      - ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    ports:
      - "3307:3306"
    environment:
      MYSQL_DATABASE: db_01
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      TZ: Asia/Tokyo
my.cnf
[mysqld]
character-set-server = utf8mb4
skip-character-set-client-handshake
collation-server = utf8mb4_general_ci
init-connect = SET NAMES utf8mb4

[mysql]
default-character-set=utf8mb4

[client]
default-character-set=utf8mb4

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?