MySQL 5.7上的MySQL字符串值错误,但5.5上没有

时间:2017-11-04 11:38:50

标签: php mysql utf-8 character-encoding

在PHP应用程序中,我试图在数据库中保存电子邮件的内容(表格为utf8mb4和collat​​ion utf8mb4_general_ci)。在我的开发环境中进行测试时,它工作正常,但在制作方面我一直遇到像这样的错误:

General error: 1366 Incorrect string value: '\xC7ALHO-...' for column 'content_html' at row 1

我检查过,我意识到我在dev上有MySQL 5.5,在prod上有5.7,我在我的dev上升级了mysql,现在我也得到了dev的错误。 问题是我不明白为什么我会收到这个错误,内容是一个非常标准的电子邮件,只有标题标识。 任何想法为什么这是5.7失败而不是5.5并且如果有任何解决方法吗?

更新:这是表格的显示全部列

ysql> SHOW FULL COLUMNS FROM received_email;
+-----------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field           | Type         | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment |
+-----------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id              | int(11)      | NULL               | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| skill_id        | int(11)      | NULL               | YES  | MUL | NULL    |                | select,insert,update,references |         |
| agent_id        | int(11)      | NULL               | YES  | MUL | NULL    |                | select,insert,update,references |         |
| message_id      | longtext     | utf8mb4_unicode_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| received_date   | datetime     | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
| downloaded_date | datetime     | NULL               | NO   |     | NULL    |                | select,insert,update,references |         |
| from_name       | varchar(255) | utf8mb4_unicode_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| from_email      | varchar(255) | utf8mb4_unicode_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| subject         | longtext     | utf8mb4_unicode_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| content_html    | longtext     | utf8mb4_unicode_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| content_plain   | longtext     | utf8mb4_unicode_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| recipient       | varchar(255) | utf8mb4_unicode_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| created_at      | datetime     | NULL               | YES  |     | NULL    |                | select,insert,update,references |         |
| updated_at      | datetime     | NULL               | YES  |     | NULL    |                | select,insert,update,references |         |
| case_detail_id  | int(11)      | NULL               | YES  | MUL | NULL    |                | select,insert,update,references |         |
+-----------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+

提前致谢

2 个答案:

答案 0 :(得分:2)

我认为你可以检查两件事......

1)电子邮件内容字符集

  • 什么是电子邮件内容charset ... utf-8呢?

  • 如果没有,您是否尝试将其转换为utf-8?

2)sql模式 - 从MySql 5.5到5.7

有一些默认的更改

您可以找到更多信息: - https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html - https://serverpilot.io/community/articles/how-to-disable-strict-mode-in-mysql-5-7.html

答案 1 :(得分:0)

说明您的客户端具有latin1个字节。在连接字符串中执行此操作,或者之后通过SET NAMES latin1执行此操作。

MySQL会将C7转换为utf8等效的"在线上#34;。

不要使用任何转换功能,这可能只会让事情变得更糟,或者至少更难以解开。