MySQL 太长 varchar 截断/错误设置

标签 mysql settings varchar

我有两个 MySQL 实例。当数据太长时,第一个会在插入时截断字符串。第二个引发错误:

错误 1406 (22001):第 1 行的“xxx”列的数据太长

我希望第二个也能截断数据。 是否有任何 MySQL 设置来管理此行为?

最佳答案

您可以禁用STRICT_TRANS_TABLESSTRICT_ALL_TABLES。这允许自动截断插入的字符串。

引自 MySQL 文档。

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)

引用:MySQL Server SQL Modes

关于MySQL 太长 varchar 截断/错误设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525982/

相关文章:

php - LEFT JOIN 中的 COUNT 返回重复值

iphone - 是否可以使用 openURL 打开设置应用程序?

hibernate - 如何使 hibernate 3.5.6-Final 和内存中的 hsqldb 2.0.0 一起工作?

mysql - 对 Char 类型使用 Like 和 Concat

mysql - 如何在mysql中索引用户名

php - PHP 中的分页无法在同一页面上运行?

Python - 自动化 MySQL 索引 : passing parameter

iOS 应用程序设置包

.net - 保存和恢复表单位置和大小

java - 在 varchar 列中存储快速编码数据