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.

# wget http://jeremy.zawodny.com/mysql/mytop/mytop-1.6.tar.gz
# tar -xvf mytop-1.6.tar.gz
# cd mytop-1.6
# 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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

15 Comments

Leave a Reply
  1. Be warned: Mytop is still present in Ubuntu 20.04 repositories and it will uninstall your MariaDb server if you try to install it. This is extremely bad.

    Reply
  2. On Ubuntu 20.04 LTS, mytop comes installed with MariaDB-server, trying to install it using apt install mytop will uninstall your mariadb-server installation.

    130 root@octopuslabs /home/ubuntu # apt install mytop :(
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    The following packages were automatically installed and are no longer required:
    galera-3 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libsnappy1v5
    libtimedate-perl liburi-perl mariadb-common mariadb-server-core-10.3 socat
    Use ‘sudo apt autoremove’ to remove them.
    The following additional packages will be installed:
    default-mysql-client mysql-client-8.0 mysql-client-core-8.0
    The following packages will be REMOVED:
    mariadb-client-10.3 mariadb-client-core-10.3 mariadb-server-10.3
    The following NEW packages will be installed:
    default-mysql-client mysql-client-8.0 mysql-client-core-8.0 mytop
    0 upgraded, 4 newly installed, 3 to remove and 1 not upgraded.
    Need to get 4259 kB of archives.
    After this operation, 53.6 MB disk space will be freed.
    Do you want to continue? [Y/n]

    Reply
  3. Hi, from Costa Rica. We have a server in Debian 9 and a database MariaDB. Command “mysqld” consume all processors (100%). I tried to install mytop, but the system display a message: “pack no available, other pack mariadb-client-10.1 available, command Mytop no has a candidate for installation.

    Please help me. Thanks.

    Reply
  4. “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 
    
    Reply
  5. When I tried to install ‘mytop’ getting following error. Even I have installed required dependency – perl(Term::ReadKey)

    [root@localhost ~]# 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

    Reply
    • @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..

      Reply
  6. 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’

    Reply
    • @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..

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.