Home Linux ServerTools Monitoring MySQL/MariaDB with Zabbix Agent

Monitoring MySQL/MariaDB with Zabbix Agent

by Thạch Phạm
Published: Last Updated on

Monitoring MySQL/MariaDB with Zabbix Agent with 2 simple steps.


Continuing with the Zabbix series, then in this article, AZDIGI will show you how to monitor MySQL/MariaDB with Zabbix Agent on your server. You can check out the previous articles of the Zabbix series here.

Before going into MySQL/MariaDB monitoring setup, you need to ensure that on the server to be monitored, MySQL/MariaDB has successfully installed Zabbix Agent . If you have not installed it, you can refer to the instructions below:

Configuration Guide

Step 1: Configure MySQL

  • Create User
AZDIGI Tutorial
mysql -uroot -p
Enter password:
GRANT USAGE ON *.* TO 'user'@'%' IDENTIFIED BY 'pass';
  • Declare the newly created User/Password

You proceed to create a zabbix folder and create an additional .my.cnf file inside the zabbix folder by following the two commands below:

AZDIGI Tutorial
mkdir /var/lib/zabbix
vi /var/lib/zabbix/.my.cnf

Then copy the content below into the .my.cnf file you just created (replace it with your User/Password)

user = zbx_monitor
password = zabbix
  • Check configuration

    Check the file /etc/zabbix/zabbix_agentd.conf has the line below (if not, please add it).
AZDIGI Tutorial

Next, you check in the directory /etc/zabbix/zabbix_agentd.d/ there will be a file userparameter_mysql.conf. If you haven’t already, you need to manually create this file and add the following content:

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix mysql -N | awk '{print $$2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[<database>,<table>,<type>].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix mysql -N'

UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
  • Restart Zabbix Agent
AZDIGI Tutorial
sudo systemctl restart zabbix-agent

Step 2: Add Host and Templates MySQL/MariaDB

Now you proceed to add Host and Templates MySQL/MariaDB to the Zabbix server. At the Zabbix Server interface, go to

Configuration >> Host >> Create Host

Set up server monitoring with Zabbix Server

Now you need fill in the necessary information as shown below:

Monitoring MySQL/MariaDB with Zabbix Agent
Click Add to update the configuration.

As shown below, you have completed the configuration.

Monitoring MySQL/MariaDB with Zabbix Agent

Thus, AZDIGI has shown you how to configure MySQL/MariaDB monitoring on Zabbix in the most detail so that you can easily monitor your server and handle it quickly if there is a problem. Hope this article will help you, wish you success.

You can refer to other instructions at the link below:

If you need assistance, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign