简体   繁体   English

在两个不同服务器上的mysql和php中的时间

[英]Time in mysql and php on two different servers

I have my php site on a server and database on another, I want to check the time on the other server holding the database, this way i can synchronize both servers at the same time to avoid time gaps. 我在服务器上有我的php站点,在另一个服务器上有数据库,我想检查另一个拥有数据库的服务器上的时间,这样我就可以同时同步两个服务器以避免时间间隔。

For my current server i simply do time(). 对于我当前的服务器,我只是做time()。 But how i can get time for mysql database? 但是我如何获得MySQL数据库的时间呢?

This is an operational problem which needs to be solved by your operations engineers (for example, using NTP). 这是一个操作问题,您的操作工程师需要解决(例如,使用NTP)。 Operations should also monitor clock sync. 操作还应监视时钟同步。

It is reasonable to develop your application assuming that the clocks will stay (mostly) in sync. 假设时钟(大部分)保持同步,则开发应用程序是合理的。

I normally like to assume that 我通常想假设

  • Clocks will be synchronised to within a few seconds 时钟将在几秒钟内同步
  • Clocks never run backwards by more than a few seconds 时钟倒数不会超过几秒钟

I guess if you assume those, you're going to be alright. 我想如果您假设这些,那您会没事的。

However you can do 但是你可以做

SELECT UNIX_TIMESTAMP()

You can use a combination of NOW() and TIME() to fetch the time from the database server. 您可以结合使用NOW()和TIME()从数据库服务器获取时间。 Have a look at the supported date and time functions that MySQL supports. 看一下MySQL支持的日期和时间函数。

SELECT TIME(NOW());

The above should work fine for you. 上面应该适合您。

我认为您想在服务器之间进行同步,在这种情况下,最好使用NTP服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL在不同服务器上的不同时间 - Mysql different time on different servers PHP PDO-MySQL Query在两台服务器上返回不同的结果 - PHP PDO - MySQL Query brings back different results on two servers 我可以在两台使用PHP的不同服务器上使用MySql Create Select吗? - Can I use MySql Create Select on two different servers with PHP? 在不同服务器上的php / mysql连接 - php/mysql connection on different servers 是否可以一次对不同服务器上的两个不同数据库(MSSQL和MySQL)执行PHP查询? - Is it possible to perform a PHP query to two different DBs (MSSQL and MySQL) on different servers at once? 是否可以从PHP中的两个不同服务器连接两个表(一个Mysql,另一个Oracle)? - Is possible to join two tables (One Mysql, the other Oracle) from two different servers in PHP? 在不同服务器上同时导出和导入mysql - Export and import mysql at the same time on different servers 在不同服务器上的两个数据库上的 MySQL 事务 - MySQL transaction over two databases on different servers PHP/MySQL/MariaDB - TINYINT 上的单引号与无引号; 具有不同行为的两台服务器 - PHP/MySQL/MariaDB - Single quotes vs no quotes on TINYINT; two servers with different behaviour 在两个不同位置运行的两台 mysql 服务器之间的数据库链接 - database link between two mysql servers running in two different locations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM