Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On windows I used to use Bitvise Tunnler to foward all traffic on my PC's localhost:33306 over an SSH connection to my server - and then from there to the mysqlserver:3306 server database.

PC:33306 -> server:3306 -> databaseserver:3306

Now that I'm using linux I find that it is easy to SSH anywhere anytime with:

ssh user@site.tld

However, I'm not sure how to replicate this port forwarding using the ssh options. If it was just from one computer to another I think I could do something like this...

ssh -L 33306:localhost:3306


I have tried connecting using the following SSH and the connection seems to work.

ssh -L 33306:localhost:3306

But phpMyAdmin throws this error when trying to connect to the other server

#1045 - Access denied for user '[[user]]'@'localhost' (using password: YES)

Then I tried

ssh -L

and phpMyAdmin threw this error

#1045 - Access denied for user '[[user]]'@'localhost' (using password: YES)

running netstat -an | more shows

tcp6       0      0 ::1:33306               :::*                    LISTEN   

Again, the process flow should look like this:

mypc -> server -> otherdbserveronprivatelan
share|improve this question
up vote 3 down vote accepted

This should do:

ssh -L 33306:databaseserver:3306

share|improve this answer
Well, it opens the SSH channel and it doesn't complain about anything. But how do I know it's working? Trying to use phpmyadmin over it isn't working so I need to know if that is my config or if the connection didn't take. – Xeoncross Feb 21 '10 at 22:43

It did work. However, I was still using "localhost" instead of "" when trying to connect.

For the command line ssh, this is

ssh -L

You then open connections in your mysql frontend to port 3333. Note that it must be, not localhost, as the later would use UNIX domain sockets.

share|improve this answer

This is not a ssh issue but rather a MySQL one. For MySQL, you need to ensure that the user has been granted access to that database. This is typically done with a:

GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'host' IDENTIFIED BY 'password';

The main thing to note here is the 'host' setting. Since you are tunneling over SSH, you need to be 'username'@'localhost' in order to work. The wildcard setting of 'username'@'%' will not work for localhost connections.

share|improve this answer
Thanks, but as stated already, the problem was using localhost instead of because of UNIX domain sockets. – Xeoncross Feb 24 '10 at 17:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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