MySQL silently truncate your data?

MySQL silently truncate your data?

The fact is if you are not using the correct SQL mode, MySQL may silently truncate your data without telling you and when you realize that you already incurred a great loss.

Ref: http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

The solution is:

Include STRICT_TRANS_TABLES or STRICT_ALL_TABLES. The difference is that the
former will only enable it for transactional data storage engines like InnoDB.

STRICT_ALL_TABLES, as an error during updating a non-transational table will result in a partial
update, which is probably worse than a truncated field.

Setting the mode to TRADITIONAL includes both these and a couple of related issues
(NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO) You can set the mode using:

On the command line:
–sql-mode=”TRADITIONAL”

In /etc/mysql/my.cnf:
sql-mode=”TRADITIONAL”

At runtime:
SET GLOBAL sql_mode=”TRADITIONAL”
SET SESSION sql_mode=”TRADITIONAL”
Just say no to databases that happily throw away your data

Leave a Reply

Your email address will not be published. Required fields are marked *

two × one =