Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' 解决方法

时间:2022-06-19 02:07:50

1. 代码

SHOW VARIABLES LIKE 'character_set_%'; 查看一下 显示

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

| Variable_name | Value |

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

| character_set_client | utf8|

| character_set_connection | utf8|

| character_set_database | latin1 |

| character_set_results | utf8|

| character_set_server | latin1 |

| character_set_system | utf8 |

| character_sets_dir | /home/jh/mysql/share/mysql/charsets |

2. 代码

SHOW VARIABLES LIKE 'collation_%';

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

| Variable_name | Value |

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

| collation_connection | utf8_swedish_ci |

| collation_database | latin1_swedish_ci |

| collation_server | latin1_swedish_ci |

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

红色字体部分为问题部分,解决方法如下:

set character_set_database =utf8;

set character_set_results =utf8;

set character_set_server =utf8;

set character_set_system =utf8; --此处utf-8也可以

然后执行:

SET collation_server = utf8_general_ci;

SET collation_database = utf8_general_ci;

执行完以后,请检查mysql数据库下的每个库,表,字段是否都是utf8,如果不是话,改成utf8格式;3. 修改mysql安装目录下的my.ini文件

[mysql]

default-character-set=utf8

配置好后,重启mysql。

另外存储过程也需要注意一下。