亂碼問題一直是困擾程式設計師最心煩的問題之一,今天網上查詢了一些資料,把mysql的字元編碼設定總結如下.
一:首先修改mysql中的配置檔案my.ini,
在[mysql]標籤中修改default-character-set=utf8
在[client]標籤中新增default-character-set=utf8
在[mysqld]標籤中修改default-character-set=utf8
在[mysqld]標籤中新增character_set_server = utf8
#表名不區分大小寫(此與編碼無關)
lower_case_table_names = 1
新增標籤[mysql.server]和[mysql_safe] 並分別在標籤下新增
default-character-set=utf8
命令列輸入 net stop mysql
命令列輸入 net start mysql
命令列輸入mysql -uroot -p*** 進入
命令列輸入show variables like 'character\_set\_%';[用於檢視mysql編碼方式]
+--------------------------+--------+
| 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 |
+--------------------------+--------+
顯示了所有的編碼方式;
還可以對資料庫的編碼方式進行修改
命令列輸入 alter database test character set 'gbk';
+--------------------------+--------+
| variable_name | value |
+--------------------------+--------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
+--------------------------+--------+
這樣就設定了test資料庫的表的編碼方式為gbk了
假如想把character_set_filesystem 也改為utf8;
命令列輸入 set character_set_filesystem=utf8;
命令列輸入 set character_set_database=utf8;
命令列輸入 show variables set 'character\_set\_%';
+--------------------------+-------+
| variable_name | value |
+--------------------------+-------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
+--------------------------+-------+
但是對於 character_set_filesystem 這個檔案的編碼 在下次啟動後依然為
+--------------------------+--------+
| 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_set_client和character_set_filesystem等已經在配置檔案裡設定了,這裡修改的只對當前頁面有效。
參考資料
mysql字符集設定
show variables like char show variables like collation 2.修改編碼 set variable name value set character set connection utf8 3 顯示建立資料庫資訊 show create databa...
mysql 字符集設定
1.檢視mysql能夠支援的多種字符集 show character set 檢視mysql能夠支援的字符集的校對規則 show collation show collation like utf8 2.檢視當前字符集及校對 show variables like character set sho...
MySQL字符集設定
一 mysql字符集設定 1 系統變數 character set server 預設的內部操作字符集 character set client 客戶端 資料使用的字符集 character set connection 連線層字符集 character set results 查詢結果字符集 ch...