当前位置:   article > 正文

mysql h 字符集_#MySQL问题--字符集问题

(gbk_chinese_ci,implicit) and (utf8mb4_general_ci,coercible) for operation

78b01d2b2d86590a285da58cc1268f89.png

问题描述:执行SQl语句

SQL:select * from searchdicts  where word = '㒰桂平';

异常:java.sql.SQLException: Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='

原因:字符集问题,两表编码方式不一致。

查看字符集:

mysql> show variables like 'char%';

+--------------------------+----------------------------------+

| Variable_name | Value |

+--------------------------+----------------------------------+

| character_set_client | gbk |

| character_set_connection | gbk |

| character_set_database | gbk |

| character_set_filesystem | binary |

| character_set_results | gbk |

| character_set_server | latin1 |

| character_set_system | utf8 |

| character_sets_dir | /Data/apps/mysql/share/charsets/ |

+--------------------------+----------------------------------+

8 rows in set (0.01 sec)

解决:查询SQL过程中进行字符转换

a6b0346518737d1efcb00acb95e88ff9.png

设置字符集;set names 'gbk';

select * from searchdicts where word = '㒰桂平' collate utf8mb4_general_ci;

模式:

select * from table_a a left join table_b b on CONVERT(a.field_a USING utf8) COLLATE utf8_unicode_ci = b.field_b

备注:utf8mb4_general_ci字符集是包含gbk_chinese_ci,属于范围更广的字符集。

select * from searchdicts where word = '仝桂平';

select * from searchdicts where word = '㒰桂平';

影响:查询时间会受损。

select * from searchdicts where word = '孟卫平';

耗时:0.006s

select * from searchdicts where word = '孟卫平' collate utf8mb4_general_ci;

耗时:0.886s

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/548336
推荐阅读
相关标签
  

闽ICP备14008679号