啟動mysql後,以root登錄mysql isher@isher-ubuntu:~$ mysql -u root
>show variables like 'character%'; #執行編碼顯示:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
在某些時候,我們續要修改mysql默認數據庫的編碼,以保證某些遷移的程序可以正常顯示,編輯my.cnf文件進行編碼修改,windows可以直接用Mysql Server Instance Config Wizard 進行設置
在linux下修改3個my.cnf的1個/etc/mysql/my.cnf文件
找到客戶端配置[client] 在下面添加
default-character-set=utf8 默認字符集為utf8
在找到[mysqld] 添加
default-character-set=utf8 默認字符集為utf8
init_connect='SET NAMES utf8' (設定連接mysql數據庫時使用utf8編碼,以讓mysql數據庫為utf8運行)
修改好後,重新啟動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/ |
+--------------------------+----------------------------+
此方法用於標准mysql版本同樣有效,對於/etc/my.cnf文件,需要從mysql/support-files的文件夾cp my-large.cnf一份到/etc/my.cnf
對於Ubuntu的用戶,如果是使用 Synaptic 安裝的,則直接在 /etc/mysql/my.cnf