1. 程式人生 > >MySQL設定uft8mb4格式,儲存Emoji表情

MySQL設定uft8mb4格式,儲存Emoji表情

檢視mysql字符集

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';

檢視資料庫字符集

show create database test;

臨時設定字符集(重啟後失效)

# 客戶端字符集
set character_set_client=utf8mb4;
# 連結字符集
set character_set_connection=utf8mb4;
# 資料庫字符集
set character_set_database=utf8mb4;
# 結果字符集
set character_set_results=utf8mb4; # 伺服器字符集 set character_set_server=utf8mb4; # 系統字符集 set character_set_system=utf8mb4; # 連結校對 set collation_connection=utf8mb4_general_ci; # 資料庫校對 set collation_database=utf8mb4_general_ci; # 伺服器校對 set collation_server=utf8mb4_general_ci;

修改配置檔案 my.conf

如沒有[client] [mysql] [mysqld]需手動新增

[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'

重啟

service mysql restart