4
0
All the computers involved are Mac OS X 10.6.x machines.
I am on computer A, and have mysql running on it, and can connect to it as A~ $ mysql -u punkish -p database
and so on.
I have access to computer B that also has mysql running on it. I can ssh into B over port 2200 with ssh key pairs set up, and once in, I can connect to the db like so
A~ $ ssh -p 2200 punkish@B
B~ $ mysql -u punkish -p database
However, I want to set up port forwarding over ssh on my computer so all requests made for mysql on port 3307 on my computer A are actually sent to port 3306 on B. This will allow me to use a gui program (Quantum GIS) that wants to connect to mysql, but can't do it over a tunnel. So, I do the following
A~ $ ssh -p 2200 -L 3307:B:3306 punkish@B
B~ $
The above logs me right into B. I am not sure if the tunnel is established, but I am assuming it is. However, the following fails (in another terminal
A~ $ mysql -P 3307 -u punkish -p
Enter password:
ERROR 1045 (28000): Access denied for user 'punkish'@'localhost' (using password: YES)
Here is the interesting thing -- I have another gui program called Sequel Pro (a desktop MySQL client for Mac OS X), and that is able to make a connection to mysql@B over ssh just fine. So, I know something works... I just don't know how.
Answering my own question (because I can't answer in less than 8 hours)
I figured out a solution, but I don't understand why. Here goes --
I was using the following command to make a tunnel
user@compt_A ~$ssh -p 2200 -L 3307:compt_B:3306 ssh_user@compt_B cat -
I have to change the above to
user@compt_A ~$ssh -p 2200 -L 3307:127.0.0.1:3306 ssh_user@compt_B cat -
Now the following works
user@compt_A ~$mysql -P 3307 -p -h 127.0.0.1 -u <db user@compt_B>
The reason it doesn't make sense to me is because the first command says, "establish an SSH tunnel over port 2200, forwarding local port 3307 to port 3306 on computer B" and that makes more sense than, "establish an SSH tunnel over port 2200, forwarding local port 3307 to port 3306 on 127.0.0.1"
Nevertheless, it works.
Oh, fwiw, if I use the first command, then the mysql command fails with the message
ERROR 1130 (HY000): Host 'compt_A' is not allowed to connect to this MySQL server
1ok, I tried
telnet localhost 3307
and I think it worked because I immediately got a connection, and it also told be it was using OpenSSH. However, if I trymysql -P 3307 -p -h 127.0.0.1 -u punkish
I am prompted for a password, and then I get the errorERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
– punkish – 2011-07-08T19:44:40.817