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.

link|improve this question
Are you able to provide the output of iptables-save? Can you also try to telnet to the host using the non-localhost IP address of the machine (so, for example 192.168.1.1)? – MIfe Nov 15 '11 at 21:39
feedback

2 Answers

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.

link|improve this answer
mysql -h localhost -u username -p works fine but mysql -h 127.0.0.1 -u username -p says ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (110) – Bakhtiyor Nov 15 '11 at 20:43
How to see whether it is started with --skip-networking or not? – Bakhtiyor Nov 15 '11 at 20:43
If you log in on localhost, do SHOW VARIABLES LIKE 'skip_networking' – DTest Nov 15 '11 at 20:45
I have ubuntu and have revised my.cnf for skip-networking parameter. I didn't find any record saying skip-networking. – Bakhtiyor Nov 15 '11 at 20:46
SHOW VARIABLES LIKE 'skip_networking' is showing skip_networking | OFF | – Bakhtiyor Nov 15 '11 at 20:47
show 3 more comments
feedback

Here is a total shot in the dark

service iptables stop

See if the firewall is interfereing

Also check allowed hosts

cat /etc/hosts
link|improve this answer
sudo service iptables stop is saying iptables: unrecognized service. However I did sudo service ufw stop but still having the same problem. What about /etc/hosts I don't know how to see allowed hosts. – Bakhtiyor Nov 15 '11 at 21:09
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.