问题描述:数据库字符编码为GBK,Spring Boot服务编码为UTF-8,导致服务在查询数据库的时候会出现如下异常。
(1267, "Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")
现象:
SELECT * FROM searchdicts WHERE word = 'xiao er急诊科'
SELECT * FROM searchdicts WHERE word = '消⼃'
SELECT * FROM searchdicts WHERE word = '陈㬢'
(1267, "Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='")
解决方案:执行语句,强制将表的编码格式转化为UTF-8
alter table table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
备注:此操作有一定的风险,需要谨慎
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。