设置MySQL完整支持Unicode
MYSQL UTF8 不支持4字节编码
Turns out MySQL’s utf8 charset only partially implements proper UTF-8 encoding. It can only store UTF-8-encoded symbols that consist of one to three bytes; encoded symbols that take up four bytes aren’t supported.。
如果出现如下错误
| Warning | 1366 | Incorrect string value: ‘\xF0\x9D\x8C\x86’ for column ‘column_name’ at row 1 |
则应该是编码问题
CharacterSet选择utf8mb4
Change the character set and collation properties of the databases, tables, and columns to use utf8mb4 instead of utf8.
For each database:
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
For each table:
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
For each column:
ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
#(Don’t blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. The above line is just an example for a VARCHAR
column.)