Tuesday, May 7, 2013

ERROR 1271 (HY000): Illegal mix of collations for operation...

The following MySql error occurs when you try to make operation on two fields with different collations. To check the field collation you can use the show create query:

mysql> show create table words;

CREATE TABLE `words` (
  `word` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Here, the collation is utf8_unicode_ci. To change the collation use the following query:

mysql> alter table words modify word varchar(20) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL

or

mysql> alter table words change word word varchar(20) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL

No comments:

Post a Comment