Tag Archives: MySQL

Check the uptime of a MariaDB or MySQL database

To check the uptime of a MariaDB or MySQL database, you can use the following queries:

1. Query Using STATUS Command

Run this query to get the uptime directly in seconds:

SHOW STATUS LIKE 'Uptime';

Output Example:

Variable_nameValue
Uptime432000
  • Value: The number of seconds since the MariaDB/MySQL server started.

2. Query for Formatted Uptime (Days, Hours, Minutes, Seconds)

For a more user-friendly output:

SELECT
    SEC_TO_TIME(VARIABLE_VALUE) AS uptime_formatted,
    VARIABLE_VALUE AS uptime_in_seconds
FROM
    performance_schema.global_status
WHERE
    VARIABLE_NAME = 'Uptime';

Output Example:

uptime_formatteduptime_in_seconds
5:00:00:00432000
  • uptime_formatted: Shows uptime in days:hours:minutes:seconds.
  • uptime_in_seconds: The raw uptime value in seconds.

3. Using sysinfo for Server Start Time

If you want to calculate uptime based on the server start time:

SELECT 
    NOW() AS current_time,
    FROM_UNIXTIME(UNIX_TIMESTAMP() - VARIABLE_VALUE) AS server_start_time
FROM
    performance_schema.global_status
WHERE
    VARIABLE_NAME = 'Uptime';

Output Example:

current_timeserver_start_time
2025-01-19 14:00:202025-01-14 14:00:20

Notes:

  • For MariaDB: These queries work for most versions as they are based on standard MySQL functions.
  • For MySQL: The performance_schema table may need to be enabled if it’s not active by default.