Web Server Can't Connect to Database Server

I have a web server (Ubuntu 14.04 LTS) and a database server (Ubuntu 12.04 LTS). UFW is enabled on both. The web server allows all outgoing traffic. The database server only allows incoming requests on 3306 for the private IP address of the web server. I've also tried disabling UFW on both servers, but the following results are the same.

I'm unable to connect to MySQL from the web server. It hangs on SYN_SENT (using tcptrack) and fails after a short time.

I'm trying to connect using mysql -u <username> -h <database-private-ip> -D <database-name> -p</database-name></database-private-ip></username> from the web server.

It fails with the error ERROR 2003 (HY000): Can't connect to MySQL server on '<database-private-ip>' (110)</database-private-ip>

I'm able to connect to mysql from the database server with the same credentials (as expected). The bind-address in my.cnf is set to 0.0.0.0. And I can ssh from the web server to the database server.

Can anyone offer some guidance on how to get these two communicating successfully?

1 Reply

MySQL not allowing user to connect from remote machine:- By default MySql creates root user id with admin access. But root id's access is limited to localhost only. This means that root user id with correct password will not work if you try to access MySql from a remote machine. To solve this problem, you need to allow either the root user or some other DB user to access MySQL from remote machine. You can use wildcard character % to specify any remote machine.

OR

Check if machine's local firewall is not enabled. And if its enabled then make sure that port 3306 is open.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct