Results 1 to 3 of 3

Thread: [SOLVED] Connection refused on MySql SSH tunnel

  1. #1
    Join Date
    Aug 2007
    Location
    California, USA
    Beans
    10
    Distro
    Ubuntu

    [SOLVED] Connection refused on MySql SSH tunnel

    I have 64-bit Ubuntu 7.10 server running as a virtual machine in VMWare Server on a 64-bit Ubuntu 7.10 desktop. On the server VM I have installed MySql and sshd and want to connect to MySql via a tunnel from the desktop. VMWare Server I installed from VMWare's site; all the other bits on the server VM and desktop machine are from Ubuntu packages. ~/.ssh/config contains
    Code:
    LocalForward 3306 server_VM_name:3306
    When I run this command
    Code:
    mysql -u root -p -h 127.0.0.1 mysql
    on the client over the tunnel I get this error:
    Code:
    Lost connection to MySQL server at 'reading initial communication packet', system error: 0
    Simultaneously, on the server VM's console I see
    Code:
    channel 5: open failed: connect failed: Connection refused
    When I run the same command on the server, mysql successfully starts. This tells me the tunnel is working but mysqld won't accept the connection. /etc/mysql/my.conf contains
    Code:
    bind-address = 127.0.0.1
    and does not have the skip-networking setting.

    I have used ssh tunnels with Linux and Windows many times without much trouble. In fact, I have successfully tunnelled an http connection from the desktop to lighttpd running on the server VM.

    Any idea what I'm doing wrong or missing?

  2. #2
    Join Date
    Aug 2007
    Location
    California, USA
    Beans
    10
    Distro
    Ubuntu

    Re: Connection refused on MySql SSH tunnel

    Quote Originally Posted by evanb View Post
    Code:
    LocalForward 3306 server_VM_name:3306
    It turns out that this was the problem. I failed to fully understand that "server_VM_name" is applied by the server's sshd from THE SERVER's perspective. That is, from the server a connection is made to "server_VM_name". To MySQL this looks like an outside connection, which my configuration does not allow.

    The correct forward string is
    Code:
    LocalForward 3306 127.0.0.1:3306
    This looks like (is, actually) a connection to a local TCP port, which is allowed.

    (Notice that using "localhost" instead of "127.0.0.1" won't work due to MySQL's treatment of "localhost" as a request for a Unix socket connection, which can't be made from a tunnel or any remote machine.)

    What's funny (in retrospect) is that I (re)discovered this when I looked at a ssh configuration file at work and found that I'd had, and solved, this problem maybe a year ago. D'oh!

  3. #3
    Join Date
    Jan 2005
    Location
    London, UK
    Beans
    647

    Re: [SOLVED] Connection refused on MySql SSH tunnel

    Thank you so much

    No one else seems to have solutions or answers and this works like a charm.
    Forums Search :: Ubuntu Wiki :: Google.com

    “Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime”

    Registered Linux user no. 391068

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •