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.

MySQLで日本語を含むレコードを挿入する際に出たエラーの解決法

Posted at

環境

  • MySQL 8.0.31
  • Docker Desktop 4.4.4
  • MySQL Workbench 8.0.30

背景

勉強目的でDockerにDBのコンテナを作り、いろいろ操作する中で日本語を含むレコードを挿入しようとしたら、エラーが出て挿入できなかった。エラーの解決に苦労したので、ナレッジとして残しておきたいと思い、記事を記載することにした。

テーブルの定義

dummyテーブル

Column Type
id int
dummycol verchar(45)

実行したSQL

INSERT INTO `dummy` (`id`, `dummycol`) VALUES ('2', 'あ');

エラー内容

ERROR 1366: 1366: Incorrect string value: '\xE3\x81\x82' for column 'dummycol' at row 1

「あ」という文字列ではなく「\xE3\x81\x82」という文字列で表示されているので、文字コード関連で怒られてるっぽい。

原因

MySQL Workbenchで見ると、Character Setがlatin1になっていたのが原因だった。
キャプチャ.PNG

解決法

Character Setをutfmb4に変えてあげると、無事SQLが通るようになった。
試してないけど、utf8でもいけるはず。

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?