Reputation: 1586
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?
Upvotes: 24
Views: 56324
Reputation: 199
I had to do this recently for system dashboard. This is what I came up with. If you have mysql your would remove mariadb with mysqld
/usr/bin/systemctl status mariadb | grep Active | cut -f2 -d\; | sed 's/ ago//g'
Hope this helps someone in the future.
Upvotes: 0
Reputation: 8706
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 |
+----------------+---------------------+----------------------------+-------------+
Upvotes: 8
Reputation: 87
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.
Upvotes: 7
Reputation: 2612
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
Upvotes: 35
Reputation: 578
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)
Upvotes: 0