Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when changing column type TIMESTAMP to DATETIME in MySQL?

Tags:

mysql

I want to convert a column data type from TIMESTAMP to DATETIME in a table with more than one million of lines.

Is it possible? Is it slow? Will I loose the old information or MySQL can convert this automatically? Can I just do an alter table or may I do something different?

like image 448
sudhakar reddy karukala Avatar asked Nov 12 '22 21:11

sudhakar reddy karukala


1 Answers

Is it possible? - Yes

Is it slow? - It will probably take a while.

The difference between TIMESTAMP and DATETIME is explained a bit over here: Should I use field 'datetime' or 'timestamp'?

Generally, I don't think changing a type is a smart thing to do unless you are really left without any other options. You will lose data that you actually want to keep or data that needs to exists will be created. This data is most likely not going to be what you need it to be.

like image 162
Ruben Avatar answered Nov 15 '22 05:11

Ruben