Skip to content

Zabbix MySQL Monitoring

If you found this page, you were probably like me and spent a day trying to get this to work..Hopfully this should get you there. First you will need the new template_db_mysql_agent template from Zabbix. Download the xml and import the template into Zabbix. Now copy the UserParameters from the template_db_mysql.conf into notepad and edit it like the example below.

We are replacing -h”$1″ -P”$2″ with –defaults-extra-file=/etc/zabbix/.my.cnf

UserParameter=mysql.ping[*], mysqladmin --defaults-extra-file=/etc/zabbix/.my.cnf ping
UserParameter=mysql.get_status_variables[*], mysql --defaults-extra-file=/etc/zabbix/.my.cnf -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s --defaults-extra-file=/etc/zabbix/.my.cnf version
UserParameter=mysql.db.discovery[*], mysql --defaults-extra-file=/etc/zabbix/.my.cnf -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql --defaults-extra-file=/etc/zabbix/.my.cnf -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='$3'"
UserParameter=mysql.replication.discovery[*], mysql --defaults-extra-file=/etc/zabbix/.my.cnf -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql --defaults-extra-file=/etc/zabbix/.my.cnf -sNX -e "show slave status"

Now paste the edited code inside the zabbix_agentd.conf under UserParameters.

Next create a file in /etc/zabbix/ and name it .my.cnf

Edit the file with:

[client]
user=zbx_monitor
password=password

Now after a restart of the Zabbix agent MySQL should start reporting.