Troubleshooting “Illegal mix of collations” error in mysql

前端 未结 17 2611
一生所求
一生所求 2020-11-22 08:11

Am getting the below error when trying to do a select through a stored procedure in MySQL.

Illegal mix of collations (latin1_general_cs,IMPLICIT) and

17条回答
  •  独厮守ぢ
    2020-11-22 08:32

    If the columns that you are having trouble with are "hashes", then consider the following...

    If the "hash" is a binary string, you should really use BINARY(...) datatype.

    If the "hash" is a hex string, you do not need utf8, and should avoid such because of character checks, etc. For example, MySQL's MD5(...) yields a fixed-length 32-byte hex string. SHA1(...) gives a 40-byte hex string. This could be stored into CHAR(32) CHARACTER SET ascii (or 40 for sha1).

    Or, better yet, store UNHEX(MD5(...)) into BINARY(16). This cuts in half the size of the column. (It does, however, make it rather unprintable.) SELECT HEX(hash) ... if you want it readable.

    Comparing two BINARY columns has no collation issues.

提交回复
热议问题