用java程序insert中文,出现Incorrect string value: '\xD6\xD0\xB9\xFA' for column 'name' at row 1 问题,肯定是字符集问题,启动MySQLInstanceConfig.exe重新配置,设置字符集先后为utf8和gbk,(修改my.ini效果相同)重启服务后问题依然存在,输入SQL:SHOW VARIABLES LIKE 'character_set_%'
显示
character_set_client | gbk
|
character_set_connection | gbk
|
character_set_database | latin1
|
character_set_filesystem | binary
|
character_set_results | gbk
|
character_set_server | gbk
|
character_set_system | utf8
|
character_sets_dir | C:\Program Files\MySQL\MySQL Serve
怀疑character_set_database一栏有问题,没找到直接查看单个数据库编码的命令,MySql可以定义每个数据库的编码格式,于是ALTER一下
alter database 库名 character set gbk;
show variables like 'character%';
character_set_client | gbk
|
character_set_connection | gbk
|
character_set_database | gbk
|
character_set_filesystem | binary
|
character_set_results | gbk
|
character_set_server | gbk
|
character_set_system | utf8
|
character_sets_dir | C:\Program Files\MySQL\MySQL Server
测试正常了
+-----------+----------+------+ | code | name | date | +-----------+----------+------+ | 600033.ss | 福建高速 | NULL | +-----------+----------+------+