MySQL太长的varchar截断/错误设置 [英] MySQL too long varchar truncation/error setting

查看:448
本文介绍了MySQL太长的varchar截断/错误设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two MySQL instances. The 1st one truncates strings on insert when data is too long. The 2nd one raises an error:

ERROR 1406 (22001): Data too long for column 'xxx' at row 1

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

I want the 2nd one to truncate the data as well. Is there any MySQL setting to manage this behavior?

推荐答案

您可以禁用STRICT_TRANS_TABLESSTRICT_ALL_TABLES.这样可以自动截断插入的字符串.

You can disable STRICT_TRANS_TABLES and STRICT_ALL_TABLES. This allows the automatic truncation of the inserted string.

MySQL Documantation的报价.

严格模式控制MySQL如何处理in中的无效或缺失值 数据更改语句,例如INSERT或UPDATE.值可以是 无效有几个原因.例如,它可能有错误的数据 列的类型,否则可能超出范围.缺少值 当要插入的新行不包含非NULL值时 定义中没有明确的DEFAULT子句的列. (为一个 NULL列,如果缺少该值,则插入NULL.)

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服务器SQL模式

这篇关于MySQL太长的varchar截断/错误设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆