Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL 5.5 & 5.6 default values

I'd like some clarification on the behaviour of default values in MySQL 5.5 & 5.6. Lets say we have the following table on a MySQL 5.5 server:

CREATE TABLE `test` (
`TestColumn` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB DEFAULT CHARSET=utf8;

I am able to run the following query without issue:

INSERT INTO `test` VALUES (NULL);

Which creates the following row:

 TestColumn
 2014-02-20 14:55:05

Now if I repeat the same test on a MySQL 5.6 server, the insert fails:

Error Code: 1048
Column 'TestColumn' cannot be null

I understand that timestamp automatic initilisation has changed in 5.6 (http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html), but what I can't work out is how to replicate the behaviour seen in 5.5 in 5.6.

Not sure if it matters but our 5.6 server has explicit_defaults_for_timestamp set to ON.

Ideally what I'm after is a solution to this, but if anyone has a better understand and can explain it that would be useful as well.

Thanks.

EDIT: We are using MySQL 5.6.13

like image 252
BombTodley Avatar asked Feb 20 '14 15:02

BombTodley


People also ask

Is MySQL 5.5 still supported?

On December 31st, 2018, MySQL version 5.5 entered End of Life status. Any server currently running MySQL 5.5 will not receive any updates, bug fixes, or security patches for MySQL until MySQL is updated to a version 5.6 or later.

What is MySQL 5.5 command line client?

MySQL is a fast, easy-to-use relational database. It is currently the most popular open-source database. It is commonly used in conjunction with PHP scripts to create powerful and dynamic server-side applications.

How do I install MySQL 5.5 on Windows 10 64-bit?

Step 1: Go to http://www.mysql.com/downloads/ and download MySQL Community Server. Choose your appropriate Operating System/X64/X86 as shown in the below Screenshot. Step 2: I've downloaded 64-Bit Windows msi file. Double Click on the msi file, you'll be welcomed with the Installation screen as seen below.


1 Answers

The behavior you showed above in 5.5 was actually a bug. This was fixed in 5.6.11. Check out the release notes for 5.6.11 at the very bottom. It was part of bugs 68472 and 16394472 (which I can't actually find a link to).

If you turn the explicit_defaults_for_timestamp flag off, it SHOULD work as it did in 5.5

This was the exact same issue that I had with our DB when we updated from 5.5 to 5.6.

like image 66
Boerema Avatar answered Oct 18 '22 07:10

Boerema