i've been trying to gain remote access to MySQL on a server. I am running into problems, i cannot seem to get the port forwarded, here are some of the steps i've made:

i've told MySQL to listen to all IPs by setting 'bind-address =' in my.cnf.

trying to forward the port, i've done various commands:

to allow access to port 3306 from all IPs:

ufw allow 3306

to allow access to port 3306 on specific remote IP addresses:

ufw allow from <remote IP> to any port 3306

netstat tells me that MySQL is listening on 3306 to all IPs, ufw tells me that 3306 is accessible by all IPs.

i have created a remote test user for MySQL that is accessible by any IP:

CREATE USER 'testuser'@'%' IDENTIFIED BY 'mypassword'

all privileges were granted.

i still cannot connect to MySQL remotely, using http://ping.eu/port-chk/ i can check if the port is open on the server, it is not!

is there something other than the ufw commands that i need to use to forward this port?

thank you!

  • 1
    You don't give out enough information on your network connection, so one cannot say for sure. What does ufw status tell? – Tero Kilkanen Jul 22 '15 at 16:16
  • 3306 ALLOW Anywhere. which i think means any IP is allowed access to 3306. There are a variety of status like this, including specific IP addresses ALLOWed to 3306. and one Anwhere ALLOW <remote ip> which should allow that specific IP address access to all ports. – jonathan Jul 22 '15 at 16:32
  • Can you show the complete output of ufw status? The order of directives has effect on the working of firewall too. – Tero Kilkanen Jul 22 '15 at 16:33
  • ok, so i used iptables -A INPUT -p tcp --dport 3306 -j ACCEPT, initially nothing worked, but after restarting the server something happened that made it work! isn't the above line nearly the same as the ufw commands i was using? as in, isn't ufw an interface into the iptables firewall? – jonathan Jul 22 '15 at 16:41
  • Yes, ufw is another tool to handle the same Linux firewall. When you use -A option, it adds the rule to the end of the rule chain. If some earlier rule already matches the packet, this rule might never be reached. That is why you must be careful with the order too. – Tero Kilkanen Jul 22 '15 at 16:43

Your Answer

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

Browse other questions tagged or ask your own question.