1. 程式人生 > >centOS7下的MySQL編碼設定

centOS7下的MySQL編碼設定

1,進入編輯my.cnf

vi /etc/my.cnf

2,在[mysql]下新增(沒有手動新增一項,要在mysqld上面)

default-character-set=utf8

3,在[mysqld]下邊新增以下內容

character-set-server=utf8

init_connect='SET NAMES utf8'

4,重啟MySQL

sudo service  mysqld restart

進入mysql 檢視字元編碼

show variables like '%character%';

mysql> show variables like '%character%'; +--------------------------+----------------------------+ | Variable_name            | Value                      | +--------------------------+----------------------------+ | character_set_client     | utf8                       | | character_set_connection | utf8                       | | character_set_database   | utf8                       | | character_set_filesystem | binary                     | | character_set_results    | utf8                       | | character_set_server     | utf8                       | | character_set_system     | utf8                       | | character_sets_dir       | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)