简体   繁体   English

数据太长,无法显示第1行的MySQL 5.6列

[英]Data too long for column at row 1 mysql 5.6

I am using MySql 5.6 in production for my application. 我正在为我的应用程序在生产中使用MySql 5.6。 Now what happens is there is one field on the form in application which has data type char(2) table and its maximum length for input type is 25. Now when user types in characters more than 2 and hit save it prompts that 现在发生的事情是,应用程序中的表单上存在一个字段,该字段的数据类型为char(2)表,输入类型的最大长度为25。现在,当用户键入的字符数超过2个并点击保存时,它将提示您

在此处输入图片说明

So I searched and found here that if I need to make this without error I need to switch MySQL mode to not use STRICT and hence I set sql_mode in my.cnf file and tried. 因此,我在这里搜索并发现,如果需要确保没有错误,请切换MySQL模式以不使用STRICT,因此我在my.cnf文件中设置了sql_mode并尝试了。 But still I am getting same error. 但是我仍然遇到同样的错误。 Here is my.cnf looks like: 这是my.cnf的样子:

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

I am using MySql 5.6 I am not getting what I am missing here. 我正在使用MySql 5.6,但没有得到我所缺少的内容。 I want that error to disappear. 我希望该错误消失。

EDIT: 编辑:

I did SET GLOBAL sql_mode = '' and then did show variables; 我做了SET GLOBAL sql_mode = '' ,然后show variables; Here is output: 输出如下: 在此处输入图片说明 But still getting same error. 但是仍然出现相同的错误。

I found solution to this issue, which is given below: 我找到了解决此问题的方法,如下所示:

You can solve error by adding property jdbcCompliantTruncation=false in JBoss datasource like: 您可以通过在JBoss数据源中添加属性jdbcCompliantTruncation = false来解决错误,例如:

jdbc:mysql://localhost:3306/dbName?zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false

Note : When you have more than one properties to set as shown above you can separate them using & 注意 :如上图所示,如果您要设置多个属性,则可以使用&

You can set the system variable sql_mode with sql: 您可以使用sql设置系统变量sql_mode:

SET GLOBAL sql_mode = '';

If it is a INSERT statement, the error will persist even with non-STRICT sql mode. 如果它是INSERT语句,即使使用非STRICT sql模式,该错误也将持续存在。

In this case, you need to modify ur column data type definition to allow longer data input, or modify your query. 在这种情况下,您需要修改ur列数据类型定义以允许更长的数据输入,或者修改查询。

You can modify ur query like this to truncate the data by yourself, since MySQL is not handling it automatically. 您可以像这样修改ur查询以自行截断数据,因为MySQL不会自动处理它。

INSERT ... VALUES( ..., LEFT('...',2));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM