As of MySQL 5.0, there is an option sql_mode
you can set, either in the my.cnf
or during startup (--sql-mode='<option>'
) or during a running session. When you set it to
sql_mode=STRICT_ALL_TABLES
mysql will not issue a warning and insert the wrong value anyways, but it will refuse your statement with an error.
See also in the manual
Example:
mysql> create table asdf (id int);
Query OK, 0 rows affected (0.13 sec)
mysql> insert into asdf value ('Hello');
Query OK, 1 row affected, 1 warning (0.38 sec)
mysql> show warnings;
+---------+------+-----------------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: 'Hello' for column 'id' at row 1 |
+---------+------+-----------------------------------------------------------+
1 row in set (0.02 sec)
mysql> select * from asdf;
+------+
| id |
+------+
| 0 |
+------+
1 row in set (0.03 sec)
mysql> set SESSION sql_mode=STRICT_ALL_TABLES;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into asdf value ('Hello');
ERROR 1366 (HY000): Incorrect integer value: 'Hello' for column 'id' at row 1
mysql>