1

I have two servers:

  • server1: 192.168.0.2
  • server2: 192.168.0.3

They are both CentOS 6. I installed MySQL on both two servers.

I can ping server2 from server1

$ ping 192.168.0.3

I can connect MySQL server with host on server2

# (server2)
$ mysql -h 192.168.0.3 -u root -p

But I can't connect server2 from server1:

# (server1)
$ mysql -h 192.168.0.3 -u root -p
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.3' (113)

My my.cnf on server2:

# /etc/my.cnf
[mysqld]
...
bind-address = 0.0.0.0

Off course restart it: service mysqld restart

My iptables on server2:

# /etc/sysconfig/iptables
...
-A INPUT -p tcp --dport 3306 -j ACCEPT
...

Off course restart it: service iptables restart

I did this on server2:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
FLUSH PRIVILEGES;

When did mysql_secure_installation on server2, I allowed remote root connect.

Everything I think good. But can't connect server2 from remote. Why?

6
  • Have you verified that it's listening on 192.168.0.3? netstat -an | grep tcp | grep 3306
    – Philᵀᴹ
    Apr 20 '17 at 7:29
  • @Philᵀᴹ Yes. The result: tcp 0 0 192.168.0.3:3306 0.0.0.0:* LISTEN. Apr 20 '17 at 7:40
  • Have a look in your my.cnf file and comment out if there is a line containing skip-networking. Temporarily stop firewalls on both servers sudo service iptables stop and sudo service ip6tables stop. Once this is done, can you post any error messages you get when trying to connect?
    – thatsaru
    Apr 20 '17 at 14:07
  • @thatsaru In my my.cnf file there isn't a skip-networking setting. Even I stoped the firewall the result was the same. I think the reason is my two virtual machines network setting. Apr 21 '17 at 3:13
  • @foo_bar - didn't realise you had virtual machines. So are these both on your desktop/laptop? Also, which virtual technology are you using VMWare/VirtualBox etc.
    – thatsaru
    Apr 21 '17 at 8:01

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.