一切都是utf8mb4_unicode_ci,但对于操作“=”,得到非法的排序规则混合(utf8mb4_unicode_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)

问题描述 投票:0回答:1

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

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

这是查询,从 json 文件读取值,

json_decode()
d,然后作为占位符传入。是
Egor🤩
。原始文本似乎是 utf8 格式,但我也尝试将输入字符串转换为 utf8 只是为了确定,它并没有改变错误。

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_ci
。 我的表格排序规则也设置为
utf8mb4_unicode_ci
。 我的列排序规则也设置为
utf8mb4_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 collation
1个回答
0
投票

几天前我遇到了完全相同的问题,甚至使用相同的表情符号🤩(而❤️一直工作得很好)。结果 connection 的字符集已设置为

utf8
并且应该设置为
utf8mb4

© www.soinside.com 2019 - 2024. All rights reserved.