Problem description:
The front end uses date.now () to get a timestamp (13 bits, accurate to milliseconds, shape 1607048228655),
Create_time, ‘create_time’ int(10) unsigned NOT NULL DEFAULT ‘0’ COMMENT ‘create_time’,
The front end failed to retrieve the timestamp from the database.
Error: ER_WARN_DATA_OUT_OF_RANGE: Out of range value for column ‘create_time’ at row 1
The error message is clear: the value of the create_time column is out of range
Question why
In mysql, int storage is limited in scope.
The signed range is integer data (all numbers) from -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647) and the unsigned range is 0 to 4294967295. A bit is 4 bytes in size.
Obviously, the 13-bit timestamp taken by the front end is out of this range, causing an error.
Problem solving
Change the create_time field type from int(10) to int(13) or even int(20) is not allowed!
Why not? I can’t save int of 10, so IF I make it a little bit longer, I can save int of 20, right? (hahaha, that’s what I thought at the beginning, and I even suspected that there was something wrong with mysql at one point)
Again, I don’t understand mysql’s int type. In fact, int is declared as
According to the width of the
Which is independent of the range of values that can be stored in the data type. Just because you can declareInt(20)
Does not mean that you can store up to 10^20 values in it:
The real solution:
1. Before storing the data, process the data, save 10 bits, accurate to second, unless special needs, 99.9% of the demand is not necessary to be accurate to millisecond;
Mysql > change int(10) to datetime/bigint(20);
> ALTER TABLE blog modify column create_time datetime;
Copy the code