1 +--------------------------+---------------------------------+ 2 | Variable_name | Value | 3 +--------------------------+---------------------------------+ 4 | character_set_client | utf8 | 5 | character_set_connection | utf8 | 6 | character_set_database | utf8 | 7 | character_set_filesystem | binary | 8 | character_set_results | utf8 | 9 | character_set_server | utf8 | 10 | character_set_system | utf8 | 11 | character_sets_dir | D:"mysql-5.0.37"share"charsets" | 12 +--------------------------+---------------------------------+
mysql默認字符集可否進行修改呢?答案是確定的,下面就將教您兩種修改mysql默認字符集的方法,但願對您學習mysql默認字符集方面能有所啓迪。mysql
(1) 最簡單的修改方法,就是修改mysql的my.ini文件中的字符集鍵值,sql
如 default-character-set = utf8
character_set_server = utf8數據庫
修改完後,重啓mysql的服務,service mysql restart學習
使用 mysql> SHOW VARIABLES LIKE 'character%';查看,發現數據庫編碼均已改爲utf8編碼
(2) 還有一種修改mysql默認字符集的方法,就是使用mysql的命令spa
1 mysql> SET character_set_client = utf8 ; 2 mysql> SET character_set_connection = utf8 ; 3 mysql> SET character_set_database = utf8 ; 4 mysql> SET character_set_results = utf8 ; 5 mysql> SET character_set_server = utf8 ; 6 7 mysql> SET collation_connection = utf8 ; 8 mysql> SET collation_database = utf8 ; 9 mysql> SET collation_server = utf8 ;
通常就算設置了表的mysql默認字符集爲utf8而且經過UTF-8編碼發送查詢,你會發現存入數據庫的仍然是亂碼。問題就出在這個connection鏈接層上。解決方法是在發送查詢前執行一下下面這句:rest
1 SET NAMES 'utf8';
它至關於下面的三句指令:code
1 SET character_set_client = utf8; 2 SET character_set_results = utf8; 3 SET character_set_connection = utf8;
還有一個最簡單的方法, 安裝的時候選擇字符集 .如圖server