Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Monit is configured to watch MySQL on localhost at port 3306.

check process mysqld with pidfile /var/lib/mysql/li175-241.pid
  start program = "/etc/init.d/mysql start"
  stop program = "/etc/init.d/mysql stop"
  if failed port 3306 protocol mysql then restart
  if 5 restarts within 5 cycles then timeout

My application, which is configured to connect to MySQL via localhost:3306, is running just fine and can access the database. I can even use MySQL Query Browser to connect to the database remotely via port 3306. The port is totally open and possible to connect to. Therefore, I'm pretty darn certain that it's running.

However, running monit -v reveals that Monit cannot detect MySQL on that port.

'mysqld' failed, cannot open a connection to INET[localhost:3306] via TCP

This happens consistently, until Monit decides not to track MySQL anymore, as configured.

How can I begin to troubleshoot this issue?

sudo netstat -lnp | grep mysql returns the following:

tcp        0      0*               LISTEN      14357/mysqld    
unix  2      [ ACC ]     STREAM     LISTENING     265228   14357/mysqld        /var/run/mysqld/mysqld.sock
share|improve this question
Can you please paste the output of sudo netstat -lnp | grep mysql? –  Khaled Jan 9 '11 at 8:00
@Khaled: edited in :) –  Matchu Jan 10 '11 at 2:57
Just out of curiousity, is the name of the pid file correct? After all, monit is looking for the pid file, not an actual connection to MySQL. –  John Gardeniers Jan 10 '11 at 3:35
@John: I believe it checks both. The PID check passes, and the connection test fails. –  Matchu Jan 11 '11 at 1:52
Posting this for others who have this issue. I had to open the port in my firewall to allow this as well: '-A INPUT -s -p tcp -m tcp --dport 3306 -j ACCEPT`, then reload firewall rules, restart monit, and it worked. –  leonardo Jun 29 '13 at 2:02

2 Answers 2

up vote 2 down vote accepted

'mysqld' failed, cannot open a connection to INET[localhost:3306] via TCP

This error shows that monit is trying to connect to port 3306 on localhost, which is the IP address

tcp 0 0* LISTEN 14357/mysqld

This netstat output shows that mysqld is listening on the IP address mentioned. It is not listening on localhost.

You either need to make mysqld listen on localhost as well, or you need to tell monit to check the specific IP address, rather than defaulting to localhost.

share|improve this answer
Interesting. What's the difference between and localhost? My web app can connect via localhost, so I'm probably missing something. –  Matchu Jan 11 '11 at 1:53
In the meantime, I've hardcoded the IP address, so that should do for now. Thanks! –  Matchu Jan 11 '11 at 1:58
@Matchu: the output from netstat says that mysqld is only listening on the IP address, unless you didn't paste some of the output. It also says that it's listening for incoming connections from - which is the global address. –  Daniel Lawson Jan 12 '11 at 3:43
@Matchu your webapp probably isn't connecting to localhost (, but is either using the 172.etc IP address, or connecting via a UNIX socket (which netstat also says is open). I'm pretty sure a lot of APIs will immediately prefer a socket if "localhost" is specified, which somewhat masks this issue. –  Daniel Lawson Jan 12 '11 at 3:44
Gotcha. Thanks! –  Matchu Jan 12 '11 at 13:58

Is your application running on the same server as mysql? Is Monit running on that same server?

Mysql may be blocking external connections.

share|improve this answer
All on the same server :/ –  Matchu Jan 8 '11 at 21:35
You may also need to create a monit user for mysql. Have you done that? –  Publiccert Jan 8 '11 at 21:38
I couldn't find anywhere that indicated that Monit would be actually logging into the MySQL database rather than just confirming that it was running. Where would I specify the username and password in Monit's config? –  Matchu Jan 8 '11 at 22:08
"allow admin:monit" added anywhere in your monit config should do the track, once you add the username. –  Publiccert Jan 8 '11 at 22:20
I'm fairly confident that the allow command is only permitted in areas specifying who is able to access the HTTP interface. –  Matchu Jan 8 '11 at 22:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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