Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operat

 

 

 

 

1.问题

今天又在mysql中遇到了,吐血。

 

2.解决方案

SQL最后加上

COLLATE utf8mb4_unicode_ci

复制代码

SELECT t2.cust_id as cust_id_ex,t1.* from 
(
SELECT * from credit_nigeria.apply   WHERE updateTime>"2019-11-10" 
)  t1
RIGHT JOIN  

(

SELECT cust_id from bank_nigeria.ng_trans_record WHERE update_Time>"2019-11-18 04" and update_Time<"2019-11-18 05" and pay_type="xx" 
) t2
on
t1.custid=t2.cust_id COLLATE utf8mb4_unicode_ci order by t2.cust_id, updateTime desc  ;

复制代码

在哪里加?

我也不太知道。。。都是试。表后面,字段后面,变量后面

 案例:

案例一

 

 

 

 

 

 案例二:

 

 

 

 

 

3.原理

utf8mb4对应的排序字符集有utf8mb4_unicode_ci、utf8mb4_general_ci.

utf8mb4_unicode_ci和utf8mb4_general_ci的对比:

  • 准确性:
  1. utf8mb4_unicode_ci是基于标准的Unicode来排序和比较,能够在各种语言之间精确排序
  2. utf8mb4_general_ci没有实现Unicode排序规则,在遇到某些特殊语言或者字符集,排序结果可能不一致。

但是,在绝大多数情况下,这些特殊字符的顺序并不需要那么精确。

  • 性能
  1. utf8mb4_general_ci在比较和排序的时候更快
  2. utf8mb4_unicode_ci在特殊情况下,Unicode排序规则为了能够处理特殊字符的情况,实现了略微复杂的排序算法。

但是在绝大多数情况下发,不会发生此类复杂比较。相比选择哪一种collation,使用者更应该关心字符集与排序规则在db里需要统一。

 

 

 

 

参考: 

Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operation '<>' - wqbin - 博客园
https://www.cnblogs.com/wqbin/p/11852376.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误提示是与MySQL数据库中的字符集(collation)相关的问题。它表示在进行比较操作时,出现了不同的字符集的混合。通常,这个错误会出现在数据库查询语句中的操作符(比如=、<>等)的两边使用了不同的字符集。比如,utf8mb4_general_ciutf8mb4_unicode_ci是两种不同的字符集,当它们混合使用时就会导致此错误。 解决这个问题的方法是确保在进行比较操作时,两边使用相同的字符集。可以通过在比较操作符两边使用COLLATE关键字来指定相同的字符集。 例如,如果你的查询是这样的:SELECT * FROM table WHERE column1 = 'value',你可以修改为:SELECT * FROM table WHERE column1 COLLATE utf8mb4_general_ci = 'value'。这样就可以避免字符集混合导致的错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [mysql字段编码不一致导致Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_...](https://blog.csdn.net/chen417980762/article/details/127068037)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operat](https://blog.csdn.net/guyue35/article/details/108846249)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [mysql报错Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT)](https://blog.csdn.net/summer089089/article/details/109595986)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值