1

I have a "problem" with my Monit configuration. The monitoring works as expected, but I get the following errors on the mysql error file /var/log/mysql/error.log each time the monitoring script runs :

190821 10:47:49 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:48:19 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:48:49 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:49:19 [Warning] Access denied for user ''@'localhost' (using password: NO)
190821 10:49:49 [Warning] Access denied for user ''@'localhost' (using password: NO)

Here is my monit config file :

 check process mysqld with pidfile /var/run/mysqld/mysqld.pid
   group database
   group mysql
   start program = "/etc/init.d/mysql start"
   stop  program = "/etc/init.d/mysql stop"
   if failed host localhost port 3306 protocol mysql then alert
   depend mysql_bin
   depend mysql_rc

 check file mysql_bin with path /usr/sbin/mysqld
   group mysql
   include /etc/monit/templates/rootbin

 check file mysql_rc with path /etc/init.d/mysql
   group mysql
   include /etc/monit/templates/rootbin

Is there a way to specify a username and password for the monit checks to prevent those warnings on the error log ?

mcoeur
  • 13
  • 6

1 Answers1

1

This is monit trying to connect to your MySQL instance as an anonymous user. Either you create an anonymous user (not recommended), or per the official documentation:

MYSQL

Syntax:

PROTOCOL MYSQL [USERNAME string PASSWORD string]

USERNAME MySQL username (maximum 16 characters).

PASSWORD MySQL password (special characters can be used, but for non-alphanumerics the password has to be quoted).

Username and password (credentials) are optional and if not set, Monit will perform the test using anonymous login. This can cause an authentication error to be logged in your MySQL log, depending on your MySQL configuration.

If credentials are set, Monit will login and perform a MySQL ping test. Monit does not require any database privileges, it just needs the database user. You might want to create standalone user for Monit to use when testing, for example:

CREATE USER 'monit'@'host_from_which_monit_performs_testing'
IDENTIFIED BY 'mysecretpassword';  FLUSH PRIVILEGES;

Example:

check process mysql with pidfile /var/run/mysqld/mysqld.pid
     start program = "/sbin/start mysql"
     stop program = "/sbin/stop mysql"
     if failed
        port 3306
        protocol mysql username "foo" password "bar"
     then alert
Lenniey
  • 5,090
  • 2
  • 17
  • 28
  • 1
    It's working, thank you ! I'd tried this solution before, but it didn't work. What worked this time : username and password between double quotes ! – mcoeur Aug 22 '19 at 12:34