1.可能是数据库的配置文件有问题
查看系统变量:
mysql> SHOW VARIABLES LIKE 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | E:\mysql57\share\charsets\ | +--------------------------+----------------------------+
在my.ini 配置文件的[mysqld] 部分增加如下行
character_set_server = 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 | E:\mysql57\share\charsets\ | +--------------------------+----------------------------+ 8 rows in set, 1 warning (0.02 sec)
2.可能是建表的时候,表的字符集设置有问题,可以修改为utf8
ALTER TABLE `databasename`.`tablename`
CHARACTER SET = utf8 ;
3.可能是表字段的字符集有问题,可以用下面的命令查看
> show full columns from tbname
查看字符型相关字段的 Collation 是不是没有设置为 utf8
修改命令:
ALTER TABLE tablename
CHANGE COLUMN `column_name` `column_name` CHAR(6) CHARACTER SET 'utf8' NOT NULL ;