一切都utf8mb4_unicode_ci,但为操作“=”获取排序规则 (utf8mb4_unicode_ci,IMPLICIT) 和 (utf8_general_ci,COERCIBLE) 的非法混合

Everything is utf8mb4_unicode_ci but getting Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='

提问人:Kenny Wyland 提问时间:10/21/2023 更新时间:10/21/2023 访问量:53

问:

我正在通过PHP进行查询,并从MySQL收到以下错误:

1267: Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) 
for operation '=')

这是查询,从 json 文件 d 中读取值,然后传入占位符。是的。原始文本似乎是 utf8 格式,但我也尝试将输入字符串转换为 utf8 以确保它没有更改错误。json_decode()Egor🤩

select fcid 
from herd_fieldchange
where 
    fieldvalue = ?

的表定义为:herd_fieldchange

CREATE TABLE `herd_fieldchange` (
  `fcid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  ...
  `fieldvalue` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  ...
  PRIMARY KEY (`fcid`),
  ...
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

我的整体数据库排序规则也是. 我的表排序规则也设置为 。 我的列排序规则也设置为 。utf8mb4_unicode_ciutf8mb4_unicode_ciutf8mb4_unicode_ci

mysql> show variables like "collation_database";
+--------------------+--------------------+
| Variable_name      | Value              |
+--------------------+--------------------+
| collation_database | utf8mb4_unicode_ci |
+--------------------+--------------------+
1 row in set (0.00 sec)

mysql> show table status;
+----------------------------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+----------------------+
| Name                       | Engine | Version | Row_format | Rows    | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation          | Checksum | Create_options | Comment              |
+----------------------------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+----------------------+
...
| herd_fieldchange           | InnoDB |      10 | Dynamic    | 7402938 |             89 |   662700032 |               0 |   1259978752 |   6291456 |        8143311 | 2023-10-20 14:24:24 | 2023-10-20 14:18:20 | NULL       | utf8mb4_unicode_ci |     NULL |                |                      |
...
+----------------------------+--------+---------+------------+---------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+--------------------+----------+----------------+----------------------+
47 rows in set (0.00 sec)

mysql> show full columns from herd_fieldchange;
+----------------+------------------+--------------------+------+-----+-------------------+----------------+---------------------------------+---------+
| Field          | Type             | Collation          | Null | Key | Default           | Extra          | Privileges                      | Comment |
+----------------+------------------+--------------------+------+-----+-------------------+----------------+---------------------------------+---------+
| fcid           | int(10) unsigned | NULL               | NO   | PRI | NULL              | auto_increment | select,insert,update,references |         |
...
| fieldvalue     | varchar(2000)    | utf8mb4_unicode_ci | YES  |     | NULL              |                | select,insert,update,references |         |
...
+----------------+------------------+--------------------+------+-----+-------------------+----------------+---------------------------------+---------+
9 rows in set (0.00 sec)

mysql>

关于堆栈溢出的所有其他帖子都说解决方案是确保列、表和数据库具有相同的排序规则......但是我所有的排序规则都是正确的,但我仍然收到错误。utf8mb4_unicode_ci

我错过了什么?

php mysql unicode 排序规则

评论

0赞 Rick James 10/22/2023
SHOW GLOBAL VARIABLES LIKE 'coll%';向我们显示应用上的连接参数。

答:

1赞 volkerschulz 10/21/2023 #1

几天前,我遇到了完全相同的问题,即使使用相同的表情符号🤩(虽然❤️一直工作得很好)。原来连接的字符集已设置为并且应该设置为 。utf8utf8mb4