Home > Database > Mysql Tutorial > How to Resolve MySQL Error Code 1406: Data Truncation?

How to Resolve MySQL Error Code 1406: Data Truncation?

DDD
Release: 2024-12-31 21:15:10
Original
363 people have browsed it

How to Resolve MySQL Error Code 1406: Data Truncation?

Error Code: 1406 - Data Truncation in MySQL

The "Error Code: 1406. Data too long for column" occurs when attempting to insert data into a MySQL table where the data exceeds the maximum length defined for the column's data type.

In the example provided, the TESTcol column has a data type of VARCHAR(45) and we are trying to insert a value that is 47 characters long. This exceeds the column's width of 45 characters.

Solution

To resolve this issue, ensure that the data being inserted does not exceed the maximum length allowed for the column's data type. In this case, we need to truncate the data to 45 characters.

Alternative Approach

While MySQL truncates data by default, it is possible to disable this behavior by changing the SQL mode to not use STRICT. This can be done by modifying the my.ini file or running the following SQL query:

SET @@global.sql_mode= '';
Copy after login

However, disabling STRICT mode is not recommended as it can lead to potential data integrity issues. Instead, it is better to ensure that the data being inserted adheres to the defined column widths.

The above is the detailed content of How to Resolve MySQL Error Code 1406: Data Truncation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template