1

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 [email protected]

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 [email protected]

UPDATE

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

ssh -L 33306:localhost:3306 [email protected]

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 33306:db.server.com:3306 [email protected]

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

3 Answers 3

3

This should do:

ssh -L 33306:databaseserver:3306 [email protected]

1
  • 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, 2010 at 22:43
0

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

For the command line ssh, this is

ssh -L 3333:mysqlhostname.youdomain.com:3306 [email protected]

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

http://blog.dreamhosters.com/kbase/index.cgi?area=2991

0

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.

1
  • Thanks, but as stated already, the problem was using localhost instead of 127.0.0.1 because of UNIX domain sockets.
    – Xeoncross
    Feb 24, 2010 at 17:26

You must log in to answer this question.

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