MySQL utf8mb4字符集:支持emoji表情符號 ㈠ 序言 為了應對無線互聯網的機遇和挑戰、避免 emoji 表情符號帶來的問題、 涉及無線相關的 MySQL 數據庫建議都提前采用 utf8mb4 字符集 這必須要作為移動互聯網行業的一個技術選型的要點 ㈡ 限制 需要 >= MySQL 5.5.3版本、從庫也必須是5.5的了、低版本不支持這個字符集、復制報錯 ㈢ 簡要步驟 以下是一個未升級到 5.5.3 的配置步驟: ① 備份數據庫 ② 升級 MySQL Server 到 v5.5.3+ ③ 修改 database、table和column字符集 [plain] <pre name="code" class="plain"></pre># 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.) ④ 修改 my.cnf [plain] [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' ⑤ 重啟 MySQL Server、檢查字符集 [plain] mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; +--------------------------+--------------------+ | Variable_name | Value | +--------------------------+--------------------+ | character_set_client | utf8mb4 | | character_set_connection | utf8mb4 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | utf8mb4 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | collation_connection | utf8mb4_unicode_ci | | collation_database | utf8mb4_unicode_ci | | collation_server | utf8mb4_unicode_ci | +--------------------------+--------------------+ rows in set (0.00 sec)