Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS 64 位修改 MySQL 5.5.25 預設字元集為 UTF-8 完整步驟

編輯:Linux 教學

查看當前字元集

mysql> SHOW VARIABLES LIKE 'character%';

若提示 command not found,請先登入 MySQL:mysql -u root -p。

定位或建立 my.cnf

預設配置檔路徑:/etc/my.cnf。若不存在,需從範例檔複製:

find / -iname '*.cnf' -print
cp /usr/share/mysql/my-large.cnf /etc/my.cnf

編輯 my.cnf 關鍵配置

[client]
default-character-set=utf8

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
# 注意:[mysql] 區塊下的 default-character-set 僅影響 mysql 客戶端,不影響服務端
  • character_set_server 設定服務端預設字元集。
  • init_connect 讓每個新連線自動執行 SET NAMES utf8,確保通訊字元集一致。

重啟 MySQL 生效

service mysql restart

驗證修改

重新登入 MySQL 執行 SHOW VARIABLES LIKE 'character%';,確認 character_set_server、character_set_database、character_set_connection 等均為 utf8。

補充說明

  • MySQL 5.5 系列 utf8 實為 utf8mb3,若需支援 Emoji(4 字節字符),請升級至 5.5.3+ 並使用 utf8mb4。
  • 同樣適用於完整 LNMP/Tomcat/Java 環境搭建,參考系列教程。
Copyright © Windows教程網 All Rights Reserved