码迷,mamicode.com
首页 > 其他好文 > 详细

日常问题记录--插入记录时报 Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误

时间:2015-03-28 14:09:24      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

背景:

写一个数据DB操作时,日志报Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation ‘=‘ 错误;

原因:

1、插入式代码中的数据类型为GBK;

2、DB建表时忘记修改默认的编码格式(默认为 Collation: latin1_swedish_ci 格式);

1、2结合之后,插入数据编码错误;

定位方法:

1、查看DB表的字段编码 show full columns from tablename;

技术分享

2、检查struts编码

技术分享

 

修改方法:

1、修改数据库DB的字段设置;

mysql> SHOW VARIABLES LIKE ‘character_set_%‘;
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
7 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE ‘collation_%‘;
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
依次执行:
set character_set_client =gbk;
set character_set_connection =gbk;
set character_set_database =gbk;
set character_set_results =gbk;
set character_set_server =gbk;
set character_set_system =gbk; --此处utf-8也可以
然后执行:
SET collation_server = gbk_chinese_ci
SET collation_database = gbk_chinese_ci
SET collation_connection =gbk_chinese_ci

日常问题记录--插入记录时报 Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误

标签:

原文地址:http://www.cnblogs.com/carterzhang/p/4374068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!