I have a Munin script /etc/munin/plugins/mysql_replag that queries a MySQL server to check the status of a master-slave replication:

# Plugin to monitor the Seconds_Behind_Master of replication on a MySQL slave

if [ "$1" = "autoconf" ]; then
        $MYSQL --version 2>/dev/null >/dev/null
        if [ $? -eq 0 ]
                $MYSQL $MYSQLOPTS -e '' 2>/dev/null >/dev/null
                if [ $? -eq 0 ]
                        echo yes
                        exit 0
                        echo "no (could not connect to mysql)"
                echo "no (mysql not found)"
        exit 1

if [ "$1" = "config" ]; then
        echo 'graph_title Replication lag'
        echo 'graph_args --base 1000 -l 0'
        echo 'graph_vlabel lag in secs'
        echo 'graph_category mysql'
        echo 'lag.label lag'
        exit 0

/usr/bin/printf "lag.value "
mysql $MYSQLOPTS -e 'show slave status\G' | grep Seconds_Behind_Master | awk '{print $2}'

The plugin config file is /etc/munin/plugin-conf.d/mysql_replag: (note: edited)

user root
env.mysqlopts -umyuser -pmyp4ssw0rd -h

However, the plugin config file is apparently ignored when running the plugin:

# munin-run mysql_replag 
lag.value ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

The plugin works when I remove the MySQL options from the config file and I specify them in the plugin directly via the $MYSQLOPTS variable. Why is the config file ignored?


Variables in munin are declared using env.myvariable, not env.var myvariable; try this:

env.mysqlopts -umyuser -pmyp4ssw0rd -h
  • Hmmm, strange. I now realize that my config file on the server uses the correct syntax while my question used the wrong syntax. Either I made a mistake copying or I realized my error on the server but forgot to update the question. +1 anyway as your suggestion is good even if it doesn't solve my problem. – dr01 Aug 31 '15 at 12:47
  • It is working now. It appears that I made a mistake in the config file name. Marking your answer as accepted since it allowed me to find the error. – dr01 Aug 31 '15 at 13:17

I was trying to configure mysql_queries plugin using this format, because that is what I found under /usr/share/munin/plugins/mysql_


env.mysqluser MyUser
env.mysqlpassword MyPassword

Thanks to Patrice Levesque's response I realised that some Mysql munin plugins (e.g mysql_queries) use this format:

env.mysqlopts -uMyUser -pMyPassword

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.