解决Mysql:Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

发现是字符集的问题

首先、查看mysql的my.cnf,确认为utf8

mysql> show variables like "%char%";

+--------------------------+-------------------------------------+

| Variable_name            | Value                               |

+--------------------------+-------------------------------------+

| character_set_client     | utf8                                |

| character_set_connection | utf8                                |

| character_set_database   | latin1                              |

| character_set_filesystem | binary                              |

| character_set_results    | utf8                                |

| character_set_server     | utf8                                |

| character_set_system     | utf8                                |

| character_sets_dir       | D:/MySQL Server 5.0/share/charsets/ |

+--------------------------+-------------------------------------+

8 rows in set (0.00 sec)

 

mysql> show variables like "%coll%";

+----------------------+-------------------+

| Variable_name        | Value             |

+----------------------+-------------------+

| collation_connection | utf8_general_ci   |

| collation_database   | latin1_swedish_ci |

| collation_server     | utf8_general_ci   |

+----------------------+-------------------+

3 rows in set (0.00 sec)

然后将数据库中所有编码方式改为统一:

mysql> set character_set_database=utf8;

Query OK, 0 rows affected (0.00 sec)

 

mysql> set collation_database= utf8_general_ci

重新查看字符集及数据表字段编码字符是否一致:

运行程序............

 

 

你可能感兴趣的:(解决Mysql:Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=')