Linux MySQL and MariaDB server monitoring

last updated in Categories Backup, Howto, Linux, News

Some time due to the high load MySQL or MariaDB server gets killed by Linux and Unix operating system. So we need to make sure that whenever it gets killed restart the MySQL server and send an email notification along with the status of MySQL servers. This is simple and yet effective script till sysadmins comes online and fix the issue.

Please see the monitor_mysql.bash script (download link at the end of script)

Customizing the script. Open the script in text editor such as vi, you can customize following 5 directives (read as variable):

1) MUSER="root"
Change this if your mysql admin user is not root user.

2) MPASS="SET-ROOT-PASSWORD"
Set up password, this the ONLY one you need to setup.

3) MHOST="localhost"
Setup hostname if it is not localhost

4) MSTART="/etc/init.d/mysql start"
This is default on Debain Linux, you need to setup this according to your UNIX/Linux/BSD OS. For systemd based system use systemctl start mysql command.

5) EMAILID="notification@somewhere-corp.com"
Set Email ID to send notification.

Once all done save the file and install script as cron job. For example run this script every minute or every five minutes on Linux or Unix server:

* * * * * /path/to/monitor_mysql.bash

A note about mytop

One can use the mytop app. It display MySQL/MariaDB server performance information like top format. It is a console-based tool for monitoring the threads and overall performance of MySQL and MariaDB servers. The user interface is modeled after familiar Unix top application.

How to install mytop on an Ubuntu/Debian

Run the apt-get command or apt command:
sudo apt install mytop

Install mytop on a Fedora Linux

Execute the following dnf command:
sudo dnf install mytop

Install mytop on a CentOS/RHEL/Oracle Linux

Turn on EPEL repo for mytop and run the following yum command:
sudo yum install mytop

Linux MySQL and MariaDB server monitoring with mytop

Simply run the following
mytop
Linux MySQL and MariaDB server monitoring
See mytop project home page here for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

1 comment

    Have a question? Post it on our forum!