This is not a bug. The issue is that you picked a value for a TIMESTAMP
column which does not exists in some timezones.
When the value is saved in a TIMESTAMP
column, the value gets converted to UTC, as mentioned in the documentation 11.2.2 The DATE, DATETIME, and TIMESTAMP Types:
MySQL converts TIMESTAMP
values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval.
So the entered value isn't stored directly into the column, unlike DATETIME
. Your current timezone is set to CET
, which uses daylight saving time. In this particular timezone, the time span from 2011-03-27 02:00:00
to 2011-03-27 03:00:00
does not exists as the clocks will be turned forward by one hour at 02:00:00
. But you picked the value 2011-03-27 02:17:04
which is between these time span borders. This makes it an invalid timestamp value for the CET
timezone to convert from and you get the error message:
Data truncation: Incorrect datetime value: '2011-03-27 02:17:04' for column 'timestamp' at row 1
There are several options depending on what you want to do. One option would be to check the timezone your MySQL client is using and adjust/use timestamp values which exists in the selected timezone. So your application shouldn't allow values to be entered which don't exists in the timezone you are using.
You can also change the timezone with the SET time_zone
command to a timezone which fits your needs. This can look like this:
mysql> CREATE TABLE Foobar(data TIMESTAMP NOT NULL);
Query OK, 0 rows affected (0.03 sec)
mysql> SELECT @@global.time_zone, @@session.time_zone, @@system_time_zone;
+--------------------+---------------------+--------------------+
| @@global.time_zone | @@session.time_zone | @@system_time_zone |
+--------------------+---------------------+--------------------+
| SYSTEM | SYSTEM | CET |
+--------------------+---------------------+--------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO Foobar(data) VALUES('2011-03-27 02:17:04');
ERROR 1292 (22007): Incorrect datetime value: '2011-03-27 02:17:04' for column 'data' at row 1
mysql> SET time_zone=UTC;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @@global.time_zone, @@session.time_zone, @@system_time_zone;
+--------------------+---------------------+--------------------+
| @@global.time_zone | @@session.time_zone | @@system_time_zone |
+--------------------+---------------------+--------------------+
| SYSTEM | UTC | CET |
+--------------------+---------------------+--------------------+
1 row in set (0.00 sec)
mysql> INSERT INTO Foobar(data) VALUES('2011-03-27 02:17:04');
Query OK, 1 row affected (0.00 sec)
Backup applications/tools might have settings which set/defines the timezone to use when retrieving or inserting TIMESTAMP
values.