Recently on a client site I had to fight the pain of having no way to confirm loss of data integrity when optimizing data types. Due to MySQL’s ability to perform silent conversion of data, when converting a number of columns we enabled sql_mode to catch any truncations as errors.
sql_mode=STRICT_ALL_TABLES
This ensured that should any data truncations occur, an error is thrown not a warning. The following shows an example case study for converting an INT to TINYINT UNSIGNED and shows that without sql_mode silent conversions occur.
mysql> drop schema if exists tmp; Query OK, 25 rows affected (0.40 sec) mysql> create schema tmp; Query OK, 1 row affected (0.01 sec) mysql> use tmp Database changed mysql> create table t1(i1 INT NULL); Query OK, 0 rows affected (0.15 sec) mysql> insert into t1 values(1),(2),(3),(256),(65536),(NULL); Query OK, 6 rows affected (0.06 sec) Records: 6 Duplicates: 0 Warnings: 0 …[Read more]