I am not able to connect remotely on port 3306. My hosting company says that i have to allow connection on port 3306 using iptables.

Whats the command to type on terminal

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql
ACCEPT     tcp  --  eth2947.rt.adsl.internode.on.net  anywhere            state NEW tcp dpt:mysql

Try using tcptraceroute hostname.fqdn 3306 to see if the connection is getting firewalled somewhere earlier.

The most likely issue is that mysql has the default config to not listen for IP connections (the old default, skip-networking option), or only to listen on the loopback (bind-address option). Try commenting these out if they're present and then restart mysql.


Well, it largely depends on what your current iptables ruleset looks like. Something like this should work in your /etc/sysconfig/iptables file:

-A INPUT -m state --state NEW -m tcp -p tcp -s --dport 3306 -j ACCEPT

...where is the IP address you're connecting from.

If it doesn't work, post the contents of /etc/sysconfig/iptables and I'll revise my answer.

The other option is just to connect to your mysql server via an ssh tunnel. Do do that, connect to your server with something like:

$ ssh user@host -L3306:localhost:3306

Then point your local mysql client at localhost:3306 and it'll get tunnelled through to the server. Keep in mind that you'll also need to grant access in mysql for the appropriate user/host combination.

I should add that it's generally not a good idea to expose your mysql port to the internet unless you absolutely need to. The ssh tunnel option is a much better way to connect remotely.

  • I still can't connect , i have added the output on the post. Actually i can't even connect even if i am on that server as well – John Apr 8 '10 at 3:08
  • 3
    Well if you can't connect directly from the server itself, it's not an iptables issue. Are you user mysqld is running? How are you trying to connect? What happens when you try to connect? – EEAA Apr 8 '10 at 3:14
  • This was the response from the hosting company ----------------It is definitely and iptables. I stopped the iptables and I can telnet to port 3306. I started the iptables and I can not telnet to port 3306. I checked the iptables rules and there is no exception for port 3306. – John Apr 8 '10 at 3:32
  • 1
    Well from the rules you posted above, it looks like you're allowing mysql traffic in. Perhaps you need to add a rule to let it back out. I'll repeat what I said before, though, try the ssh tunnel thing. You'll be quite pleased. – EEAA Apr 8 '10 at 3:42
  • 1
    ACtually my main aim is to connect mysql through php , so i was just testing using shell. whats the command to add rule to back out data – John Apr 8 '10 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy