Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
* latin1のカラムにlatin1の文字
```
mysql57> SET NAMES latin1;
Query OK, 0 rows affected (0.00 sec)
mysql57> INSERT INTO t2 VALUES ('a'), ('あ');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
```
* latin1で接続すれば読める。
```
mysql57> SELECT val, HEX(val) FROM t2;
+------+----------+
| val | HEX(val) |
+------+----------+
| a | 61 |
| あ | E38182 |
+------+----------+
2 rows in set (0.00 sec)
```
* utf8mb4で読もうとすると化ける
```
mysql57> SET NAMES utf8mb4;
Query OK, 0 rows affected (0.00 sec)
mysql57> SELECT * FROM t2;
+---------+
| val |
+---------+
| a |
| a?? |
+---------+
2 rows in set (0.00 sec)
```
* utf8mb4に無理矢理変換するけど、utf8mb4で読もうとすると化けたまま。
```
mysql57> ALTER TABLE t2 CONVERT TO CHARACTER SET utf8mb4;
Query OK, 2 rows affected (0.04 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql57> SELECT val, HEX(val) FROM t2;
+---------+----------------+
| val | HEX(val) |
+---------+----------------+
| a | 61 |
| a?? | C3A3C281E2809A |
+---------+----------------+
2 rows in set (0.00 sec)
```
* latin1で読もうとすると読める不思議。
```
mysql57> SET NAMES latin1;
Query OK, 0 rows affected (0.00 sec)
mysql57> SELECT val, HEX(val) FROM t2;
+------+----------------+
| val | HEX(val) |
+------+----------------+
| a | 61 |
| あ | C3A3C281E2809A |
+------+----------------+
2 rows in set (0.00 sec)
```
* character_set_databaseの設定も影響してるかも(´・ω・`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment