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 5 years have passed since last update.

laradock環境下のmysqlで文字化けしちゃった

Posted at

はじめに

laradockで環境構築を行ってからseederでデータ投入。
その後にmysqlコンテナに入り、データが入っているか確認すると英語や数字は問題なく表示された。が、
日本語のデータが文字化けしていた。
それを解決するのにハマってしまったので、備忘録としてこの記事を書きたいと思う。

原因

mysqlにてstatusコマンドで文字コードを確認。

utf8
Db     characterset:	utf8
Client characterset:	latin1
Conn.  characterset:	latin1```

上記にあるように
```Client characterset:	latin1
Conn.  characterset:	latin1```

ClientとConnの文字コードがlatin1になってたのが原因だとわかった。
# 解決策
latin1をutf8にするためにlaradock/mysql/my.cnfに下記を追加した。
```character-set-server=utf8
[client]
default-character-set=utf8

それから

docker-compose down build mysql
docker-compose up -d mysql```
でmysqlコンテナを再起動すると解決した。
# 参考サイト
https://qiita.com/luccafort/items/0553c589dcc6459746bc
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?