查看mysql數據庫編碼:mysql
show variables like 'character%';sql
mysql> show variables like 'character%'; +--------------------------+-------------------------------------------------+ | Variable_name | Value | +--------------------------+-------------------------------------------------+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ | +--------------------------+-------------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) mysql>
能夠看出database和server都採用了latin1編碼,不支持中文,咱們須要把它修改成utf-8。數據庫
除了這兩個,其它的以下:編碼
| 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 | E:\0Develop\mysql-5.7.15-winx64\share\charsets\
在mysql安裝目錄下,將 my-default.ini 複製一分保存爲 my.ini
作以下修改:spa
主要看紅色框裏的內容:.net
[mysqld] character-set-server=utf8 collation-server=utf8_general_ci [mysql] default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 [client] default-character-set = utf8
結果,查看編碼:code
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 | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ | +--------------------------+-------------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) mysql>
mysql> show create database test; +----------+-----------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------+ | test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ | +----------+-----------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> alter database test default character set utf8; Query OK, 1 row affected (0.00 sec) mysql> show create database test; +----------+---------------------------------------------------------------+ | Database | Create Database | +----------+---------------------------------------------------------------+ | test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+---------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
參考:http://blog.csdn.net/u013474104/article/details/52486880server