Changing MySQL Collation

By Morten Møller Riis

April 18 2012 10:45 CET

MySQL will by default set collation to latin1_swedish_ci.

If you are seeing errors like (here using the Mysql2 gem on Ruby):

Mysql2::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation ‘like’

Then it would probably be a good idea to use the same collation.

To change the server collation you can add the following under the [mysqld] section in my.cnf:

            character_set_server = utf8
            collation_server = utf8_general_ci
            

Restart the server after this.

Next you need to convert your tables to utf8 (remember to do a mysqldump or similar backup first).

            ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;