4

I have an Azure virtual machine holding an Ubuntu system, with MySQL server and I want to access the database from a web application. When I installed mysql-server, I executed

$ iptables -I INPUT -p tcp --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT
$ iptables -I OUTPUT -p tcp --sport 3306 -m state --state ESTABLISHED -j ACCEPT

to allow tcp connections. In the file /etc/mysql/my.cnf I added bind-address = 168.63.178.87, which is the "Virtual IP Address" that Azure panel tells me.

In mysql, the user I am using to connect has all privileges on the database needed (I think):

mysql> SHOW GRANTS FOR 'user'@'%';
+-------------------------------------------------------------------------------------------------------------------+
| Grants for user@%                                                                                            |
+-------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY PASSWORD 'pass_ommited' |
| GRANT ALL PRIVILEGES ON `database`.* TO 'user'@'%'                                                          |
+-------------------------------------------------------------------------------------------------------------------+

But when the application tries to connect to the database, I recieve the error:

 CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2003] Can't connect to MySQL server on '168.63.178.87' (4) 

(It's a Yii framework application, in case it matters).

I have full SSH access to the virtual machine, using the given IP address and a specific port. Azure also tells me the "Internal IP address", which is 10.78.28.85. I have tried binding the MySQL server to that address and to 0.0.0.0, but none has worked.

I suspect the problem is the redirection made to access my specific instance in the server, but I don't know how to solve it.

2 Answers 2

6

I finally solved it. The problem was that I didn't have an endpoint in Azure.

I have created the endpoint with the 3306 port and restarted mysql-server with sudo restart mysql

Other mistake I had is that I needed to set the bind address as the Internal IP Address of the server.

2
  • Other mistake I had is that I needed to set the bind address as the Internal IP Address of the server. how do I bind on a Windows Box? Commented Dec 31, 2013 at 14:32
  • In my case, binding to the internal IP address worked. Commented Jan 26, 2015 at 2:23
0

Endpoint is not enough! Just spent 4 hours solving this problem. You also need to verify that your server has a firewall rule for MySql port, and most importantly, the rule is PUBLIC:

as shown here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .