Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC.'

通过jdbc向mysql插入汉字时报了这个错
解决办法:
1、将数据库和表的编码改为utf-8

alert database kpi character set utf8 

alter table address convert to character set utf8
2、vim /etc/my.cnf 加入

[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

3、重启mysql(/etc/init.d/mysql stop /etc/init.d/mysql start)
4、进入mysql查看字符集(mysql>show variables like ‘character_set_%’;)
Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC.'_第1张图片
5、重新建表

mysql> create table ipflow(ip varchar(20), times int) ENGINE=InnoDB DEFAULT CHARSET=utf8;#这样就可以了
#下面是删除列与增加列,与上面的无关
mysql> alter table ipflow add city varchar(20);
mysql> alter table ipflow drop column city;

你可能感兴趣的:(mysql,MySQL)