linux下/etc/mysql/my.cnf(windows下my.ini) 


[client] 下添加 

default-character-set=utf8 默认字符集为utf8 

[mysqld] 添加 

default-character-set=utf8 默认字符集为utf8 

#character-set-server=utf8 

collation-server=utf8_general_ci 

init_connect='set collation_connection=utf8_general_ci' 

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/ |