Home > Database > Mysql Tutorial > Can MySQL be Configured to Truncate Excessively Long Data Consistently?

Can MySQL be Configured to Truncate Excessively Long Data Consistently?

DDD
Release: 2024-11-07 02:24:03
Original
919 people have browsed it

Can MySQL be Configured to Truncate Excessively Long Data Consistently?

MySQL Data Truncation or Error Handling

MySQL handles data truncation differently depending on its settings. In some cases, it truncates excessive data silently, while in others, it throws an error.

Issue:

A user has two MySQL instances where one instance truncates data when it's too long, and the other raises an error.

Question:

Is there a way to configure MySQL to consistently truncate too long data, similar to the first instance?

Answer:

Yes, disabling the SQL mode settings STRICT_TRANS_TABLES and STRICT_ALL_TABLES will enable automatic truncation of inserted strings.

Implementation:

SET GLOBAL sql_mode = '...,-STRICT_TRANS_TABLES,-STRICT_ALL_TABLES';
Copy after login

Explanation:

STRICT_TRANS_TABLES and STRICT_ALL_TABLES enforce stricter data validation rules. Disabling these settings relaxes the validation, allowing for automatic truncation.

Reference:

MySQL Server SQL Modes: https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html

The above is the detailed content of Can MySQL be Configured to Truncate Excessively Long Data Consistently?. 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