mysql服务启动时间

时间:2014-08-31 06:52:33

标签: python mysql

mysql中是否有任何变量会返回启动mysql服务的日期? 我使用以下4个步骤来获取mysql的开始日期。

mysql> select now(), unix_timestamp(now());
+---------------------+-----------------------+
| now()               | unix_timestamp(now()) |
+---------------------+-----------------------+
| 2014-08-31 12:14:09 |            1409467449 |
+---------------------+-----------------------+

mysql> show status like 'uptime';
+---------------+--------+
| Variable_name | Value  |
+---------------+--------+
| Uptime        | 242645 |
+---------------+--------+

mysql> select (1409467449  - 242645 );
+-------------------------+
| (1409467449  - 242645 ) |
+-------------------------+
|              1409224804 |
+-------------------------+

mysql> SELECT from_unixtime(1409224804 );
+----------------------------+
| from_unixtime(1409224804 ) |
+----------------------------+
| 2014-08-28 16:50:04        |
+----------------------------+

有没有办法编写将返回服务器启动时间的存储过程或函数?

我需要在python脚本中使用这个日期。

1 个答案:

答案 0 :(得分:3)

select date_sub(now(), INTERVAL variable_value SECOND) started_at
from information_schema.global_status 
where variable_name='Uptime';