LoginSignup
1
2

More than 5 years have passed since last update.

MySQLで4byteになるUTF-8文字列を検索する

Last updated at Posted at 2017-01-20

utf8mb4

MySQL 5.5.4からデータベースの文字コードにutf8mb4を指定できる

そもそもUTF-8って4byteあることあるんだ…という感想なのですが、ざっくりと非常用漢字、中国語および絵文字はこれに属するようです。

そこからMySQLの「寿司ビール問題」が出てきたんですね、Twitterで見た。

問題となりそうな文字列を16進数で検索してみる

ここを見てみると、Shift_JIS内に収まる漢字の中で、問題になりそうなのは 0xf0 から始まる文字のようだ。検索してみよう。

mysql> SELECT COUNT(*) FROM target_table WHERE HEX(target_column) LIKE '%F0%';
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
1 row in set (0.38 sec)

あんまりなかった。

1
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
1
2