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.
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.
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:
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.
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 :
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.