0
0

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 + mysql5.7】DBに日本語をINSERTできない問題の解決法

Posted at

はじめに

dockerでよくあるphp:apatchとmysql5.7で簡単な環境を作って、
CakePHPのブログチュートリアルをやっているときに
日本語の記事テキストがDBへ登録できずエラーになったので解決法を載せようと思いました。

もともとのdocker-compose.yml

docker-compose.yml
version: "3.7"
services:
  cakeapp:
    build:
      context: ./docker
      dockerfile: Dockerfile
    ports:
      - "8080:80"
    tty: true
    stdin_open: true
    volumes:
      - ./html:/var/www/html

  db:
    image: mysql:5.7
    volumes:
      - "./db:/docker-entrypoint-initdb.d"
    environment:
      MYSQL_DATABASE: hogehoge
      MYSQL_USER: hogehoge
      MYSQL_PASSWORD: hogehoge
      MYSQL_ROOT_PASSWORD: hogehoge

DBへ日本語登録できるdocker-compose.yml

db定義に一行追加するのみ

docker-compose.yml
version: "3.7"
services:
  cakeapp:
    build:
      context: ./docker
      dockerfile: Dockerfile
    ports:
      - "8080:80"
    tty: true
    stdin_open: true
    volumes:
      - ./html:/var/www/html

  db:
    image: mysql:5.7
# ここを追加
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    volumes:
      - "./db:/docker-entrypoint-initdb.d"
    environment:
      MYSQL_DATABASE: hogehoge
      MYSQL_USER: hogehoge
      MYSQL_PASSWORD: hogehoge
      MYSQL_ROOT_PASSWORD: hogehoge

以上

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?