0

I have a mysql server in linux environment with private ip. A VPN access is provided for accessing MySQL server.

I used VPN and connected through putty access and connected to mysql from CLI. But when i tried through php in wamp environment, it says

Warning: mysql_connect() [function.mysql-connect]: No connection could be made because the target machine actively refused it.

i used the following line

mysql_connect("privateip","username","pass") or die(mysql_error());

Please help me through this problem. thanks

PravinS
  • 2,640
  • 3
  • 21
  • 25
  • have you tried privateip:portnumber? – user2959229 Aug 04 '14 at 11:38
  • 1
    I would assume that your mysql server is configured to accept only connections from localhost, not from outside. That's a configuration standard, if I remember correctly. – VMai Aug 04 '14 at 11:47
  • 1
    Have a look at http://stackoverflow.com/questions/8380797/enable-remote-mysql-connection too. Second highest rating answer. – VMai Aug 04 '14 at 11:49
  • "It is not recommended to use the old mysql extension for new development, as it has been deprecated as of PHP 5.5.0 and will be removed in the future" http://uk1.php.net/manual/en/mysqlinfo.api.choosing.php – ʰᵈˑ Aug 04 '14 at 11:51
  • If your error says `actively refused it` you are getting all the way to your MySQL server, but it probably does not like the credentials. That user has to be setup to allow connections from you ip address at least or if that changes then `'user'@'%'` to allow from anywhere. BIT DANGEROUS THAT! If you do this make sure that the password is VERY STRONG. – RiggsFolly Aug 04 '14 at 14:28

1 Answers1

0

According to this thread on CodeProject, "Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. As Amit there said, it's not an issue with your code, it's an issue with your server's configuration.

I won't ask why you're having to connect via VPN (MySQL databases can be reached from anywhere, as long as your firewall allows it), but this could potentially be part of the problem here. Try connecting from outside the VPN.

If that doesn't work, then please re-ask this question (omit your code, since it isn't causing the problem) on Server Fault or Super User, as this question is currently outside the scope on Stack Overflow.

AStopher
  • 4,207
  • 11
  • 50
  • 75