How to know the MySQL uptime from commandline – 3 Methods

MySQL uptime.

In some situations, we need to check the uptime for MySQL in your server. We can not afford the downtime of a database engine. As a system engineer you must know the linux command-line options to find the uptime.

There are many ways to determine the uptime of MySQL engine.  The following command will give you the MySQL version along with the uptime of MySQL process.

What is MySQL performance tuning and what does it mean ?

MySQL has a lot of variables in its configuration. We can edit and set/alter variables to our requirements on our server. We can improve the MySQL performance by varying those values in configuration file.

A lot of methods and shell scripts are available for tuning your MySQL server. Here I am explaining the installation and usage of one shell script for tuning the MySQL.

This performance tuning shell script will help you to optimize your MySQL server on a huge traffic cPanel server. Read more..

Method I

# mysqladmin  version

Example:

# mysqladmin  version
mysqladmin  Ver 8.42 Distrib 5.5.35, for Linux on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
....
....
Server version		5.5.35-cll
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/lib/mysql/mysql.sock
Uptime:			20 days 3 hours 16 min 18 sec
Threads: 5  Questions: 12009211  Slow queries: 0  Opens: 474165  Flush tables: 1  Open tables: 400  Queries per second avg: 6.902

Method II

# mysqladmin  ver

This command is similar to “mysqladmin version”

Example:

root@web [/home]# mysqladmin  ver
mysqladmin  Ver 8.42 Distrib 5.5.35, for Linux on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
...
...
Server version		5.5.35-cll
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/lib/mysql/mysql.sock
Uptime:			20 days 3 hours 24 min 48 sec

Threads: 5  Questions: 12045578  Slow queries: 0  Opens: 474198  Flush tables: 1  Open tables: 400  Queries per second avg: 6.921

If you need to know only the MySQL uptime, then you can use grep command with the above mentioned command.

# mysqladmin  version | grep -i uptime
# mysqladmin  ver | grep -i uptime

Example:

# mysqladmin  ver | grep -i uptime
Uptime:			20 days 3 hours 27 min 37 sec

# mysqladmin  version | grep -i uptime
Uptime:			20 days 3 hours 19 min 28 sec

Method III

# mysqladmin status

This command also shows MySQL uptime along with running threads and queries, but this uptime is not in an easily understandable form. Here, uptime is recorded in seconds.
Example:

# mysqladmin status
Uptime: 1740953  Threads: 3  Questions: 12061095  Slow queries: 0  Opens: 474228  Flush tables: 1  Open tables: 400  Queries per second avg: 6.927

Cool 🙂

MySQL related:

  1. Reset mysql root password from command line
  2. Allow mysql client to access remote mysql databases
  3. Create/restore MySQL dump/backup of all the databases.
  4. How to create a database and database user from command line
  5. Create a New Database-user and Grand Permissions

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

4 thoughts on “How to know the MySQL uptime from commandline – 3 Methods

Leave a Reply

Your email address will not be published. Required fields are marked *