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

问题描述

我正在使用来自 Java 应用程序的相当简单的数据库.我们尝试使用标准的 JDBC mysql 适配器一次插入大约 200k 的文本.我们间歇性地得到一个 com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column error.

I'm working with a fairly simple database, from a Java application. We're trying to insert about 200k of text at a time, using the standard JDBC mysql adapter. We intermittently get a com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column error.

列类型为longtext,数据库排序为UTF-8.使用 MyISAM 和 InnoDB 表引擎时会出现该错误.客户端和服务器端的最大数据包大小已设置为 1 GB,因此这也不应该导致问题.

The column type is longtext, and database collation is UTF-8. The error shows up using both MyISAM and InnoDB table engines. Max packet size has been set ot 1 GB on both client and server sides, so that shouldn't be causing a problem, either.

推荐答案

检查您的 UTF-8 数据是否都是 3 字节的 Unicode.如果您有 4 字节字符(在 Unicode 和 Java 中合法,在 MySQL 5 中非法),则在您尝试插入它们时可能会引发此错误.这是应该在 MySQL 6.0 中修复的问题.

Check that your UTF-8 data is all 3-byte Unicode. If you have 4-byte characters (legal in Unicode and Java, illegal in MySQL 5), it can throw this error when you try to insert them. This is an issue that should be fixed in MySQL 6.0.

这篇关于MySQL 数据截断错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:52
查看更多