Tuesday, November 15, 2011

Illegal Mix of Collations Error in MySQL

I was doing a join statement in MySQL and had an error popup that I had not seen before.  The error i received was the following:

Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
Since I am trying to keep data segregated, I created a separate database from the one that SugarCRM had created in MySQL and created my own table.  It appears that the 2 table has different collation defaults on them.  I had no idea that was the case.  In order to examine that for each table, I ran the following command:

SHOW CREATE TABLE tblname


This gave me the information I needed.  for each table.  One of my tables showed

COLLATE = 'utf8_unicode_ci'


while the other one did not have a collate value on it.  For me, this meant hat the value was

COLLATE = 'utf8_general_ci'


So, I needed to change the default database collate type for one of them.  I decided to change it to utf8_general_ci and did so with the following command:

ALTER DATABASE dbname COLLATE = 'utf8_general_ci';


I then needed to chance my table.  So, I did this by dropping my table and recreating it.


No comments:

Post a Comment