Mytop – A Useful Tool for Monitoring MySQL/MariaDB Performance in Linux

Mytop is an open source and free monitoring program for MySQL and MariaDB databases was written by Jeremy Zawodny using Perl language. It is much similar in look and feel of the most famous Linux system monitoring tool called top.

Mytop program provides a command-line shell interface to monitor real time MySQL/MariaDB threads, queries per second, process list and performance of databases and gives a idea for the database administrator to better optimize the server to handle heavy load.

By default Mytop tool is included in the Fedora and Debian/Ubuntu repositories, so you just have to install it using your default package manager.

If you are using RHEL/CentOS distributions, then you need to enable third party EPEL repository to install it.

For other Linux distributions you can get mytop source package and compile it from source as shown.

# tar -zxvf mytop-<version>.tar.gz
# cd mytop-
# perl Makefile.PL
# make
# make test
# make install

In this MySQL monitoring tutorial, we will show you how to install, configure and use mytop on various Linux distributions.

Please note you must have running MySQL/MariaDB Server on the system to install and use Mytop.

Install Mytop in Linux Systems

To install Mytop, run the appropriate command below for your Linux distribution to install it.

$ sudo apt install mytop	#Debian/Ubuntu
# yum install mytop	        #RHEL/CentOS
# dnf install mytop	        #Fedora 22+
# pacman -S mytop	        #Arch Linux 
# zypper in mytop	        #openSUSE
Sample Output :
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.linode.com
 * epel: mirror.freethought-internet.co.uk
 * extras: mirrors.linode.com
 * updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package mytop.noarch 0:1.7-10.b737f60.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================
 Package                               Arch                                   Version                                              Repository                            Size
==============================================================================================================================================================================
Installing:
 mytop                                 noarch                                 1.7-10.b737f60.el7                                   epel                                  33 k

Transaction Summary
==============================================================================================================================================================================
Install  1 Package

Total download size: 33 k
Installed size: 68 k
Is this ok [y/d/N]: y

How to use Mytop to Monitor MySQL/MariaDB

Mytop needs MySQL/MariaDB login credentials to monitor databases and connects to the server with the root username by default. You can specify the necessary options for connecting to the database server on the command-line as you run it or in the file ~/.mytop (for convenience as explained later on).

Just run the following command to start the mytop and provide your MySQL/MariaDB root user password, when prompted. This will connect to the test database by default.

# mytop --prompt
Password:

Once you entered the MySQL root password you will see Mytop monitoring shell, similar to below.

MySQL Database Monitoring

MySQL Database Monitoring

If you would like to monitor specific database, then use the -d option as shown below. For example the below command will monitor database tecmint.

# mytop --prompt -d tecmint
Password:
Monitor MySQL Database

Monitor MySQL Database

If each of your databases has a specific admin (for example tecmint database admin), then connect using the database username and password like so.

# mytop -u tecmint -p password_here -d tecmintdb

However, this has certain security implications since the user’s password is typed on the command-line and can be stored in the shell command history file. This file can be viewed later on by an unauthorized person who might land on the username and password.

To avoid the risk of such a scenario, use the ~/.mytop config file to specify options for connecting to the database. Another advantage of this method is that you also do away with typing numerous command-line arguments each time you want to run mytop.

# vi ~/.mytop

Then add the necessary options below in it.

user=root
pass=password_here
host=localhost
db=test
delay=4
port=3306
socket=

Save and close the file. Then run mytop without any command-line arguments.

# mytop

It has a capability to show large amount of information on the screen and has many keyboard shortcut options too, check out “man mytop” for more information.

# man mytop

Read Also :

  1. Mtop (MySQL Database Monitoring) in RHEL/CentOS/Fedora
  2. Innotop to Monitor MySQL Performance

In this article, we have explained how to install, configure and use mytop in Linux. If you have any questions, use the feedback form below to reach us.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

8 Responses

  1. Therion7777 says:

    “To avoid the risk of such a scenario, use the ~/.mytop config file to specify options for connecting to the database.”

    Pf.

    # mytop --prompt -u -d 
    
  2. Alex says:

    Looking like innotop database monitoring program.

  3. Wellington Torrejais da Silva says:

    Thanks!

  4. Navin Kumar says:

    When I tried to install ‘mytop’ getting following error. Even I have installed required dependency – perl(Term::ReadKey)

    [[email protected] ~]# yum install mytop
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
    * epel: epel.mirror.net.in
    Setting up Install Process
    Resolving Dependencies
    –> Running transaction check
    —> Package mytop.noarch 0:1.7-3.b737f60.el6 will be installed
    –> Processing Dependency: perl(Term::ReadKey) >= 2.1 for package: mytop-1.7-3.b737f60.el6.noarch
    –> Finished Dependency Resolution
    Error: Package: mytop-1.7-3.b737f60.el6.noarch (epel)
    Requires: perl(Term::ReadKey) >= 2.1
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    • Ravi Saive says:

      @Navin,
      It seems the perl-Term-ReadKey package having issue with mytop package, better remove that package and try to yum mytop again and see..

  5. Sina says:

    Thanks for the article,
    But when you run mysql_secure_installation and remove the “test” database, you cannot run mytop because of these error:
    Unknown database ‘test’

    • Ravi Saive says:

      @Sina,
      No I don’t think ‘test’ database needed, but I think you must have one or two databases to run mytop command. Create a one or two database and try to run mytop command to see whether its working or not..

  6. Wellington Torrejais da Silva says:

    Thanks!!!

Leave a Reply to Navin Kumar Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.