Why can't I telnet to MySQL?

6,032

MySQL uses the UNIX socket on localhost - much faster. It won't run on a TCP port unless you tell it to do so.

Share:
6,032
Bakhtiyor
Author by

Bakhtiyor

Updated on September 18, 2022

Comments

  • Bakhtiyor
    Bakhtiyor over 1 year

    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
    unix  3      [ ]         STREAM     CONNECTED     4542200  /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.

  • Riccardo Murri
    Riccardo Murri over 12 years
    @Bakhtior yes: ufw is a simplified frontend to iptables.
  • Bakhtiyor
    Bakhtiyor over 12 years
    So, why I am not able to telnet to mysql then?
  • Riccardo Murri
    Riccardo Murri over 12 years
    @Bakhtiyor Just a clarification: you say "When trying to connect to the MySQL server I get this error ..." and then "I can connect via ... once I'm in the server" Does this mean that you're trying the telnet localhost command on a host which is not the MySQL server host?
  • Bakhtiyor
    Bakhtiyor over 12 years
    First I am connecting to the server with ssh, and then right from the server I am executing telnet command.
  • Riccardo Murri
    Riccardo Murri over 12 years
    @Bakhtiyor ...and you've shut down the firewall on the server, right?
  • Bakhtiyor
    Bakhtiyor over 12 years
    Yes, right in the server I am disabling ufw.
  • Riccardo Murri
    Riccardo Murri over 12 years
    @Bakhtiyor Sorry, then I have no clue what's happening. I'll leave the answer hanging here as the comments might provide info for someone who knows.
  • Bakhtiyor
    Bakhtiyor over 12 years
    All right @Riccardo, thx a lot for trying to help me.