Mysql – Unable to connect to remote host: Connection timed out when trying to telnet to MySQL

connectionMySQLtelnet

When trying to connect to mysql server via telnet I am getting following error:

telnet localhost 3306
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out

I tried telnet with 127.0.0.1, hostname also, but getting same error message. But I can connect with mysql -u username -p once I am in the server.

Here is the result of netstat:

netstat -na | grep mysql
unix  2      [ ACC ]     STREAM     LISTENING     4540495  /var/run/mysqld/mysqld.sock

netstat -na | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN  

What could be possible problems? If you need some more details I could provide it without any problems.

Thanks a lot.

Best Answer

Can you connect with:

mysql -h127.0.0.1 -u username -p

If not, check whether your server was started 'skip-networking' enabled:

If the server was started with --skip-networking, it will not accept TCP/IP connections at all. src

Which indicates 127.0.0.1 will not work, but localhost will. In mysql localhost and 127.0.0.1 are different hosts.

Further things to check:

  • are you running the default port (3306)? Check your my.cnf or do mysqladmin -h localhost -p variables | grep port

  • If you are running under Linux and Security-Enhanced Linux (SELinux) is enabled, make sure you have disabled SELinux protection for the mysqld process.