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.

DockerのMySQLへのinsertでError Code: 1366. Incorrect string value: 'xx' for column 'name' at row 1

Posted at

事象

日本語を含むinsert分で上記エラーが発生。

対応

以下を確認すると文字コードがlatin1になっているのが原因。

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.7.31, for osx10.15 (x86_64) using  EditLine wrapper

Connection id:		174
Current database:	xxx
Current user:		root@xxx
SSL:			Cipher in use is DHE-RSA-AES256-SHA
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.26 MySQL Community Server (GPL)
Protocol version:	10
Connection:		127.0.0.1 via TCP/IP
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
TCP port:		13307
Uptime:			2 days 3 hours 37 min 13 sec

Threads: 3  Questions: 2106  Slow queries: 0  Opens: 219  Flush tables: 1  Open tables: 212  Queries per second avg: 0.011
--------------

以下で確認したところmy.cnfがない。

docker container exec -it xxx bash
cat /etc/mysql/conf.d/my.cnf

Dockerfileが間違っていた。(mysqlではなくmusql)

ADD ./Docker/mysql/conf.d/my.cnf /etc/musql/conf.d/my.cnf

上記修正をした上で、以下でコンテナを再作成。
(再起動でも良いのだけど、もう一度マイグレーションをロールバックして、再実行するのが手間だと感じたので)

docker-compose down --rmi all --volumes
docker-compose up -d

参考

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?