Reprinted from Souldak, Weibo: @evagle
Following content
Integrated FilteringFrom the Internet:
Int
1. Occupy 4 bytes
2. After indexing, query speed is fast
3. Conditional range Search can be used using between
4. You cannot use the time function provided by MySQL
Conclusion: Suitable for data tables that require large time-range queries
Datetime
1. Take up 8 bytes of 2. Allowed to be null, the value can be customized and the system does not automatically modify its value.
3. Actual format storage (Just stores what are you having stored and retrieves the same thing which you have stored.)
4. Time zone Independent (It has nothing to deal with the TIMEZONE and Conversion.)
5. You cannot set a default value, so you must manually specify the value of the DateTime field to successfully insert the data in cases where null values are not allowed. 6. You can use the now () variable to automatically insert the current time of the system when specifying the value of a DateTime field. Conclusion: DateTime types are appropriate for recording the original creation time of the data, because no matter how you change the value of the other fields in the record, the value of the DateTime field does not change unless you manually change it. Timestamp
1. Take up 4 bytes of 2. Null values are allowed, but values cannot be customized, so null values are meaningless.
3. The timestamp value cannot be earlier than 1970 or later than 2037. This indicates that a date, such as ' 1968-01-01 ', is valid for a datetime or date value but is not valid for the timestamp value, and is converted to 0 if assigned to such an object.
4. Values are saved in UTC (It stores the number of milliseconds)
5. Time zone conversion, the current time zone is converted when stored, and then converted back to the current time zone.
6. The default value is Current_timestamp (), which is actually the current system time. 7. The database automatically modifies its value, so you do not need to specify the name of the timestamp field and the value of the timestamp field when inserting a record, you only need to add a timestamp field when you design the table, and the value of the field will automatically become the current system time when you insert it. 8. The timestamp value of the corresponding record is automatically updated to the current system time when the records in the table are modified at any later time. Conclusion: The timestamp type is suitable for recording the last modification time of the data, because the value of the timestamp field is automatically updated as soon as you change the value of the other fields in the record.
The difference and pros and cons of timestamp,datetime,int type in MySQL "reprint"