Question: how can I get mysql server uptime from the Linux command line? Answer: there are a few simple ways to check mysql server uptime from the Linux terminal, wheter you are on a vps, cloud or dedicated box, the methods are the same and they will work on most MySQL versions.
3 ways to Check MySQL server uptime from command line
There a few ways to get the mysql uptime if you are inside a Linux VPS, Cloud or Dedicated Server. Let’s explore each one of them using the mysqladmin command from the Linux terminal.
1. Use the status option against mysqladmin command
mysqladmin status -p
Paste your MySQL root password, and you should get an output similar to this:
[[email protected]:~]mysqladmin status -p Enter password: Uptime: 2800485 Threads: 1 Questions: 79097902 Slow queries: 274 Opens: 121188 Flush tables: 1 Open tables: 400 Queries per second avg: 28.244 [[email protected]:~]
As you see, using the mysqladmin status command will give you the uptime, but not in a human readeable format, as it is expressed in seconds, not even minutes or hours.
2. Check mysql uptime using mysqladmin command
mysqladmin version -p
The output should be similar to this:
[[email protected]:~]mysqladmin version -p Enter password: mysqladmin Ver 8.42 Distrib 5.x, for Linux on x86_64 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Server version 5.x Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 32 days 9 hours 56 min 55 sec [[email protected]:~]
On the last line you will notice the MYSQL uptime expressed in days, lot easier than option 1.
3. Get the uptime by using mysqladmin with ‘ver’ parameter
mysqladmin ver -p
This command is similar to “mysqladmin version” command, and will provide the exact same information.
No need to use “-p” if you have .my.cnf configured properly:
[client]
user=root
password=”ROOTPASSWORD”
From that point on mysql commands work without password. I believe this is default on cPanel systems.