Illegal mix of collations error in MySql

后端 未结 19 2047
醉梦人生
醉梦人生 2020-11-29 01:11

Just got this answer from a previous question and it works a treat!

SELECT username, (SUM(rating)/COUNT(*)) as TheAverage, Count(*) as TheCount 
FROM ratings         


        
相关标签:
19条回答
  • 2020-11-29 01:57

    Was getting Illegal mix of collations while creating a category in Bagisto. Running these two commands from @Quy Le 's answer solved the issue for me:

    --set utf8 for connection

    SET collation_connection = 'utf8_general_ci'
    

    --change CHARACTER SET of DB to utf8

    ALTER DATABASE dbName CHARACTER SET utf8 COLLATE utf8_general_ci
    
    0 讨论(0)
  • 2020-11-29 01:58

    I got this same error inside a stored procedure, in the where clause. i discovered that the problem ocurred with a local declared variable, previously loaded by the same table/column.

    I resolved it casting the data to single char type.

    0 讨论(0)
  • 2020-11-29 01:58

    In short, this error is caused by MySQL trying to do an operation on two things which have different collation settings. If you make the settings match, the error will go away. Of course, you need to choose the right setting for your database, depending on what it is going to be used for.

    Here's some good advice on choosing between two very common utf8 collations: What's the difference between utf8_general_ci and utf8_unicode_ci

    If you are using phpMyAdmin you can do this systematically by working through the tables mentioned in your error message, and checking the collation type for each column. First you should check which is the overall collation setting for your database - phpMyAdmin can tell you this and change it if necessary. But each column in each table can have its own setting. Normally you will want all these to match.

    In a small database this is easy enough to do by hand, and in any case if you read the error message in full it will usually point you to the right place. Don't forget to look at the 'structure' settings for columns with subtables in as well. When you find a collation that does not match you can change it using phpMyAdmin directly, no need to use the query window. Then try your operation again. If the error persists, keep looking!

    0 讨论(0)
  • 2020-11-29 02:01

    I was getting this same error on PhpMyadmin and did the solution indicated here which worked for me

    ALTER TABLE table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci
    

    Illegal mix of collations MySQL Error Also I would recommend going with General instead of swedish since that one is default and not to use the language unless your application is using Swedish.

    0 讨论(0)
  • 2020-11-29 02:01
    • Check that your users.gender column is an INTEGER.
    • Try: alter table users convert to character set latin1 collate latin1_swedish_ci;
    0 讨论(0)
  • 2020-11-29 02:06
    HAvING TheCount > 4 AND username IN (SELECT username FROM users WHERE gender=1)
    

    but why i am answering, you dont voted me as right answer :)

    0 讨论(0)
提交回复
热议问题