Differences and connections between the sysdate () and now () functions in MySQL

Source: Internet
Author: User

There are 5 functions in MySQL that need to calculate the value of the current time:

    1. Now. Return time, format as: 2012-09-23 06:48:28
    2. Curdate, returns the date of the time, formatted as: 2012-09-23
    3. Curtime, return time, format such as: 06:48:28
    4. Unix_timestamp, returns the time integer stamp, such as: 1348408108
    5. Sysdate, the return time, the format and time () function return times, but there are differences.
In addition to the differences that are returned by the definition itself, the other difference is that the first four functions return the start-of-execution time based on the statement, and Sysdate returns the value of the hour.

By comparison, you can find the difference between these two functions:

Now () do the following:

  1. Mysql> Select Now (), Sleep (2), now ();
  2. +---------------------+----------+---------------------+  
  3. | Now () | Sleep (2) | Now () |
  4. +---------------------+----------+---------------------+  
  5. |        2012-09-23 06:54:29 | 0 | 2012-09-23 06:54:29 |
  6. +---------------------+----------+---------------------+  
  7. 1 row in Set (2.00 sec)

The two values it returns are the same because they represent the time at which the statement started executing.


Sysdate is executed as follows:

  1. mysql> Select Sysdate (), Sleep (2), sysdate ();
  2. +---------------------+----------+---------------------+  
  3. | Sysdate () | Sleep (2) | Sysdate () |
  4. +---------------------+----------+---------------------+  
  5. |        2012-09-23 06:55:00 | 0 | 2012-09-23 06:55:02 |
  6. +---------------------+----------+---------------------+  
  7. 1 row in set (2.01 sec)

Because of this difference, we generally use now () when executing the statement, because Sysdate gets the time in real time, which could cause the main library and the return value from the library to be executed differently, leading to inconsistent master-slave data.

Other functions on it are performed as follows:

Differences and connections between the sysdate () and now () functions in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.