Linux MySQL and MariaDB server monitoring

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

See mytop project home page here for more information.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.