Illegal mix of collations error in MySql

后端 未结 19 2236
醉梦人生
醉梦人生 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:51

    Here's how to check which columns are the wrong collation:

    SELECT table_schema, table_name, column_name, character_set_name, collation_name
    
    FROM information_schema.columns
    
    WHERE collation_name = 'latin1_general_ci'
    
    ORDER BY table_schema, table_name,ordinal_position; 
    

    And here's the query to fix it:

    ALTER TABLE tbl_name CONVERT TO CHARACTER SET latin1 COLLATE 'latin1_swedish_ci';
    

    Link

提交回复
热议问题