I've been trying to set up a SSH tunnel with VPN on my macbook with Big Sur 11.2, but it doesn't seem to work.

On my linux machine, I can simply turn on the VPN and make a SSH-tunnel. Then I can just connect to the MySQL server via port 3307. If I do the same on my macbook, the SSH tunnel does connect, but I can't connect to the MySQL server on the given port.

My exact steps are:

  1. Turn on VPN so I can access the server via SSH.
  2. Run ssh -g -L 3307: user@ip_address in the terminal.
  3. Run mysql -u user -p -h [IP] -P 3307 to connect to the MySQL SSH tunnel.
  4. Error: Can't connect to MySQL server on '[IP]'.

Above works fine on my linux system, but not on my mac. I am able to SSH to the server with the command, but the tunnel itself is not working.

Is there some reason this is happening, and how should I proceed?

  • So it looks like you can connect locally, but not remotely. I’d suspect that your user is not authorized to connect to MySQL from a remote machine. Please add more info to your question: what’s the error message and which access rights does the user have that you use to connect?
    – not2savvy
    Jan 5, 2021 at 22:00
  • @not2savvy I am able to connect via SSH to the remote server and run MySQL scripts there. I updated my question.
    – Jay Wit
    Jan 6, 2021 at 7:30
  • 1
    Not too sure, but when you create the SSH tunnel between your macbook and the server, shouldn't you use the server IP address in the ssh command? And shouldn't you use the localhost IP address ( in the mysql command and not the server IP? Or maybe I'm confused... Jan 6, 2021 at 9:10
  • @SaaruLindestøkke that was it! I thought I had to connect to the VPN's IP, but that was wrong. Can you create an answer so I can accept it?
    – Jay Wit
    Jan 7, 2021 at 8:10

1 Answer 1


It appears you have swapped the local address and the remote server address around. For example this site explains it should be:

  1. Create an SSH tunnel from you client to the server:
    ssh -g -L 3307:server-ip:3306 user@server-ip
    Now port 3306 of the server is exposed on 3307 on the client.
  2. On the client connect MySQL to the 3307 port: mysql -u user -p -h 127.0.01 -P 3307
    Note that you have to connect to the local loopback address as the SSH tunnel already forwarded the connection to the client.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .