Mysql儲存emoji表情
阿新 • • 發佈:2018-12-19
儲存表情需要對應字符集支援
1.mysql支援utf8mb4的版本是5.5.3+
2.修改資料庫配置
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4' default-storage-engine=INNODB
3.修改對應資料庫、表、欄位的字符集
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE table_name CHANGE column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
表中某欄位為可以儲存表情的只需要修改該欄位的字符集即可;
在建立表時,可直接指定字符集
`title` varchar(50) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '標題',