I found this SQL query to display MySQL uptime:
SHOW GLOBAL STATUS LIKE 'Uptime';
But I get the value 2059555.
How I can convert it to days?
On MySQL prompt type this, On the last line we will find Uptime
mysql>\s
Also if needed to write a query. This will give you in hours and minutes
select TIME_FORMAT(SEC_TO_TIME(VARIABLE_VALUE ),'%Hh %im') as Uptime
from information_schema.GLOBAL_STATUS
where VARIABLE_NAME='Uptime'
Note: Above version 5.7 use performance_schema instead of information_schema
select TIME_FORMAT(SEC_TO_TIME(VARIABLE_VALUE ),'%Hh %im') as Uptime from performance_schema.global_status where VARIABLE_NAME='Uptime'
dev.mysql.com/doc/refman/5.7/en/…
Jul 28, 2017 at 15:12
SELECT ROUND(@d:=VARIABLE_VALUE/60/60/24) AS days, ROUND(@d/30.5) AS months FROM performance_schema.global_status WHERE VARIABLE_NAME = 'Uptime';
Oct 11, 2018 at 15:42
With MySQL 5.7+:
SELECT
VARIABLE_VALUE AS Uptime_seconds,
NOW() AS "Now",
NOW() - INTERVAL VARIABLE_VALUE SECOND AS "Up since",
DATEDIFF(NOW(), NOW() - INTERVAL VARIABLE_VALUE SECOND) AS "Uptime_days"
FROM performance_schema.session_status
WHERE VARIABLE_NAME = 'Uptime';
Example:
+----------------+---------------------+----------------------------+-------------+
| Uptime_seconds | Now | Up since | Uptime_days |
+----------------+---------------------+----------------------------+-------------+
| 16430228 | 2021-04-09 14:11:58 | 2020-10-01 10:14:50.000000 | 190 |
+----------------+---------------------+----------------------------+-------------+
You can run SHOW GLOBAL STATUS;
to find the value for Uptime
, represented in seconds. Divide by 86,400 (60 * 60 * 24) to convert to days.
select global status ; ERROR 1054 (42S22): Unknown column 'global' in 'field list'
DATEDIFF
to compute the number of days between two dates.
You can use MySQL Workbench (as it's free).
Go under the tab Management > server status
it will show Running since: Mon Mar 20 15:29:45 2017 (1 hour)
Uptime
server status variable, which is not something that is indicated in the question—indeed, the question indicates no understanding of how the value should be interpreted. None of the other questions resolve that problem, or even slightly help to solve it. EVEN IF the value was known to be seconds, none of those questions help to convert the output of aSHOW STATUS
command. So, again, it's not a duplicate. If you disagree TAKE IT UP ON Meta Stack Overflow.