Share the pitfalls of MySQL's current_timestamp and their solutions

Share the pitfalls of MySQL's current_timestamp and their solutions

MySQL's current_timestamp pitfall

Report an error

Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

The answers on the Internet are basically as follows, but there is no specific solution

The reason for the solution is that when you set a timestamp to on updatecurrent_timestamp, other timestamp fields need to explicitly set default values

But if you have two timestamp fields, but only set the first one to current_timestamp and the second one has no default value, MySQL can successfully create the table, but not the other way around...

My Solution

Uninstall the current lower version of MySQL and install MySQL version 5.6 or higher. MySQL version 5.7 is recommended as it is relatively stable.

mysql5.5.23 current_timestamp problem

Today I created a new table with two fields: creation time and update time. Both default values ​​are the current time. An error occurs when executing SQL.

ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

I have used this SQL in other projects and it works fine. Why can't it be executed successfully today? After confirming that there were no syntax errors in the sql, I checked the information online. It turns out that MySQL 5.5 only supports one time field in a table using CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP. But in 5.6 it supports multiple.

Original description

It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.

Solution

Remove the default creation time

Check the MySQL version number using the status command

這里寫圖片描述

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to MySQL error TIMESTAMP column with CURRENT_TIMESTAMP
  • Analyzing the MySql CURRENT_TIMESTAMP function by example
  • Detailed explanation of TIMESTAMP usage in MySQL

<<:  How to prevent the scroll bar from affecting the page width when the scroll bar appears on the page

>>:  CSS animation combined with SVG to create energy flow effect

Recommend

Vue keeps the user logged in (various token storage methods)

Table of contents How to set cookies Disadvantage...

Detailed explanation of the lock structure in MySQL

Mysql supports 3 types of lock structures Table-l...

Vue implements table paging function

This article example shares the specific code of ...

MySQL database optimization: index implementation principle and usage analysis

This article uses examples to illustrate the prin...

WeChat applet implements calculator function

WeChat Mini Programs are becoming more and more p...

Use crontab to run the script of executing jar program regularly in centOS6

1. Write a simple Java program public class tests...

XHTML introductory tutorial: text formatting and special characters

<br />This section introduces how to impleme...

Summary of Nginx location and proxy_pass path configuration issues

Table of contents 1. Basic configuration of Nginx...

Teach you how to deploy Vue project with Docker

1.Write in front: As a lightweight virtualization...

MySQL 5.7.17 installation and configuration graphic tutorial

Features of MySQL: MySQL is a relational database...

How to use html table (to show the visual effect of web page)

We know that when using HTML on NetEase Blog, we ...