Troubleshooting “Illegal mix of collations” error in mysql

前端 未结 17 2436
一生所求
一生所求 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条回答
  •  旧时难觅i
    2020-11-22 08:48

    Very interesting... Now, be ready. I looked at all of the "add collate" solutions and to me, those are band aid fixes. The reality is the database design was "bad". Yes, standard changes and new things gets added, blah blah, but it does not change the bad database design fact. I refuse to go with the route of adding "collate" all over the SQL statements just to get my query to work. The only solution that works for me and will virtually eliminate the need to tweak my code in the future is to re-design the database/tables to match the character set that I will live with and embrace for the long term future. In this case, I choose to go with the character set "utf8mb4".

    So the solution here when you encounter that "illegal" error message is to re-design your database and tables. It is much easier and quicker then it sounds. Exporting your data and re-importing it from a CSV may not even be required. Change the character set of the database and make sure all the character set of your tables matches.

    Use these commands to guide you:

    SHOW VARIABLES LIKE "collation_database";
    SHOW TABLE STATUS;
    

    Now, if you enjoy adding "collate" here and there and beef up your code with forces fulls "overrides", be my guess.

提交回复
热议问题