技术文章
使用MySQL数据库在系统升级后发生错误
org.apache.openjpa.persistence.PersistenceException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '=' {prepstmnt 63740409 SELECT t0.xid, t1.xorderColumn, t1.xavailableGroupList FROM PTL_PORTAL t0 INNER JOIN PTL_PORTAL_availableGroupList t1 ON t0.xid = t1.PORTAL_XID WHERE (t0.xid = ?) ORDER BY t0.xid ASC, t1.xorderColumn ASC} [code=1267, state=HY000]
mysql的collation大致的意思就是字符序。首先字符本来是不分大小的,那么对字符的>, = , < 操作就需要有个字符序的规则。collation做的就是这个事情,你可以对表进行字符序的设置,也可以单独对某个字段进行字符序的设置。一个字符类型,它的字符序有多个,比如:
下面是UTF8对应的字符序。
utf8_general_ci utf8
utf8_bin
utf8_unicode_ci
utf8_icelandic_ci
utf8_latvian_ci
utf8_romanian_ci
utf8_slovenian_ci
utf8_polish_ci
utf8_estonian_ci
utf8_spanish_ci
utf8_swedish_ci
utf8_turkish_ci
utf8_czech_ci
utf8_danish_ci
utf8_lithuanian_ci utf8
utf8_slovak_ci
utf8_spanish2_ci
utf8_roman_ci
utf8_persian_ci
utf8_esperanto_ci
utf8_hungarian_ci
utf8_sinhala_ci utf8
utf8_german2_ci utf8
utf8_croatian_ci
utf8_unicode_520_ci
utf8_vietnamese_ci
utf8_general_mysql500_ci
mysql的字符序遵从命名惯例。以_ci(表示大小写不敏感),以_cs(表示大小写敏感),以_bin(表示用编码值进行比较)。比如:
CREATE TABLE `issue_message` ( `id` int(11) NOT NULL AUTO_INCREMENT, `content` varchar(255) NOT NULL, PRIMARY KEY (`id`), ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
这个表下面的两个sql会出现同样的结果
select * from issue_message where content = 'Yes' select * from issue_message where content = 'yes'
如果改成下面的定义:
CREATE TABLE `issue_message` ( `id` int(11) NOT NULL AUTO_INCREMENT, `content` varchar(255) NOT NULL COLLATE utf8_bin, PRIMARY KEY (`id`), ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
原因是数据库表中的列采用不同的排序规则,查看数据库设置:
数据库默认的排序规则和表中的排序规则不一致导致.
通过调整数据库列的Collation(排序来统一排序规则)
ALTER TABLE X.ATDC_ATTENDANCE_ADMIN MODIFY COLUMN xid varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_ci NOT NULL;
也可以通过图形化直接修改.
上一篇:How to start?
下一篇:系统配置-数据库驱动JAR包更改