January 18, 2012

Mysql Mismatch Collations

When get mysql error :
Illegal mix of collations (lati1_general_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '='
try this code to SQL text :
> show variables like 'coll%'
  collation_connection | latin1_general_ci
  collation_database | latin1_swedish_ci
  collation_server | latin1_swedish_ci

there is a difference between collation_connection and collation database/server, to fix that, you must at least have collation_connection = collation_database, for it you can try with phpmyadmin :
1. Backup your database,
2. Set Mysql connection collation to latin1_general_ci,
3. Create new database and set collation to latin1_general_ci, so your collation_database is the same with collation_connection before,
4. To change two things before look for image below (red line) :





5. Now restore your backup database, and try for error again.

The way above i've been test when i get error when try to login for my application, and after change those collation type, i can login back.
Or try change my.cnf file ( /etc/my.cnf in linux , my.ini in windows )
add what default_collation you wan, see below :

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#Default to using old password format for compatibility with mysql 3.x
#clients (those using the mysqlclient10 compatibility package).
#old_passwords=1
default-collation=latin1_swedish_ci

Save file, and reload mysql.

Hope this useful, and feel free to leave comment here.
Regards,

No comments:

Post a Comment