2

For the mysql NOW() function, whose system time is used for time calculations? The host of the database or the client executing the statement?

Robert Daniels
  • 141
  • 1
  • 3

1 Answers1

2

That should be the time of the host (DB Server).

To be sure, login to MySQL from your client and run

SELECT NOW();

and then run the date() command in PHP and compare.

The NOW() and PHP date() would only be the same if you are running MySQL and Apache/NGINX on the same server.

CAPTAIN's LOG : SUPPLEMENTAL

You may also compare the difference between NOW() and SYSDATE() if you care about the datetime being deterministic.

The example in the documentation for [SYSDATE()] show how

mysql> SELECT NOW(), SLEEP(2), NOW();
+---------------------+----------+---------------------+
| NOW()               | SLEEP(2) | NOW()               |
+---------------------+----------+---------------------+
| 2006-04-12 13:47:36 |        0 | 2006-04-12 13:47:36 |
+---------------------+----------+---------------------+

mysql> SELECT SYSDATE(), SLEEP(2), SYSDATE(); +---------------------+----------+---------------------+ | SYSDATE() | SLEEP(2) | SYSDATE() | +---------------------+----------+---------------------+ | 2006-04-12 13:47:44 | 0 | 2006-04-12 13:47:46 | +---------------------+----------+---------------------+

Sorry, if this is WTMI, but just know that NOW() comes from the DB Server, not the WebServer.

Back in March of 2014, I talked about monkeying around with the server time and its effect on binary logs : Risk of changing clocktime on MySQL server host

RolandoMySQLDBA
  • 185,223
  • 33
  • 326
  • 536