mysql ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) ....

本文介绍了解决MySQL存储过程中因不同字符集引起的错误的方法。通过调整存储过程内的字符串编码为utf8mb4并指定相应的排序规则,确保了操作过程中的一致性。

迁移服务器时,重建mysql数据库,将数据库的编码格式改为了utf8mb4(见该篇),以便能够存储emoji表情.

在遇到一个执行procedure报错 :
call TigAddUserPlainPw(‘db-properties’, NULL);

ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,COERCIBLE) and (utf8mb4_unicode_ci,COERCIBLE) for operation '='

存储过程TigAddUserPlainPw代码:

create procedure TigAddUserPlainPw(_user_id varchar(2049) CHARSET utf8, _user_pw varchar(255) CHARSET utf8)
begin
    case TigGetDBProperty('password-encoding')
        when 'MD5-PASSWORD' then
            call TigAddUser(_user_id, MD5(_user_pw));
        when 'MD5-USERID-PASSWORD' then
            call TigAddUser(_user_id, MD5(CONCAT(_user_id, _user_pw)));
        when 'MD5-USERNAME-PASSWORD' then
            call TigAddUser(_user_id, MD5(CONCAT(substring_index(_user_id, '@', 1), _user_pw)));
        else
            call TigAddUser(_user_id, _user_pw);
        end case;
end 

以上建表语句中 ‘MD5-USERID-PASSWORD’ 等变量的默认编码方式需要改变,修改TigAddUserPlainPw代码:

create procedure TigAddUserPlainPw(_user_id varchar(2049) CHARSET utf8, _user_pw varchar(255) CHARSET utf8)
  begin
    case TigGetDBProperty('password-encoding')
      when CONVERT('MD5-PASSWORD' USING utf8mb4) COLLATE utf8mb4_unicode_ci then
      call TigAddUser(_user_id, MD5(_user_pw));
      when CONVERT('MD5-USERID-PASSWORD' USING utf8mb4) COLLATE utf8mb4_unicode_ci then
      call TigAddUser(_user_id, MD5(CONCAT(_user_id, _user_pw)));
      when CONVERT('MD5-USERNAME-PASSWORD' USING utf8mb4) COLLATE utf8mb4_unicode_ci then
      call TigAddUser(_user_id, MD5(CONCAT(substring_index(_user_id, '@', 1), _user_pw)));
    else
      call TigAddUser(_user_id, _user_pw);
    end case;
  end 

删除存储过程TigAddUserPlainPw,重建该存储过程。


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值