mysql_connect()失败 - 错误(4)

I developed a PHP application with MySQL and node.js implementation. I am trying to connect to my production DB like the following:

mysql_connect('54.212.117.38', 'root', '********');

This is the Error I get :

Could not connect: Can't connect to MySQL server on '54.212.117.38' (4)

I must mention that I can reach the PHPmyAdmin directly through the browser.

Moreover, On local host the application is connecting to MySQL with no problem. I also tried restarting the Apache server, shutting down the Node.js procedure...

BTW - My production server is running Ubuntu.

Does anyone has an idea on what's the reason that it doesn't work?

There is more than one possibility. Some advice:

  • Make sure the mysql server behind this IP address is running and accepting connects.
  • Make sure the user can access from your clients ip.
  • Check out if perhaps the connection process takes too long (in this case, you can try increasing the connect_timeout).
  • If nothing else helps, trace the traffic between client and server. Maybe a firewall is slightly too aggressive (I've had that once, user root was triggering an IDS rule...).

A sidenote, the mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

the problem is the firewall rules.

When you connect via Phpmyadmin, you are connecting through the web interface and internally Phpmyadmin is connecting to localhost.

  1. Check your local ip or the ip of the server that you want to connect from.
  2. Make sure you change the parameter bind-address to: bind-address = 0.0.0.0 = 0.0.0.0