Is there a way to ignore mysql ER_DATA_TOO_LONG?

Asked 2 years ago, Updated 2 years ago, 108 views

Mysql server has been newly installed. In the past, I used it without any problems, but on the new server, ER_DATA_TOO_LONG error when inserting into mysql.

In the old server, things that go over the number of characters are just truncated and stored, but in the new server, they seem to make errors when they go over the number of characters, so what's the option to just cut and save like before?

mysql er_data_too_long

2022-09-21 16:34

1 Answers

Try turning off STRICT_TRANS_TABLES and STRICT_ALL_TABLES. Then, we will automatically execute the exceeded string.

MySQL document Quote:

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.) Strict mode also affects DDL statements such as CREATE TABLE.

Change Mode

SET GLOBAL sql_mode = 'modes';
SET SESSION sql_mode = 'modes';

Check Current Mode

SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;

Example

mysql> SET sql_mode=';! turn off mode
mysql> SET sql_mode='STRICT_TRANS_TABLES'; ! Turn on STRICT_TRANS_TABLES mode
mysql> SET sql_mode='STRICT_ALL_TABLES';;! Turn on STRICT_ALL_TABLES mode


2022-09-21 16:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.