I can ssh onto the remote server and login without a problem.

I'm trying to connect to a remote mysql db over a ssh tunnel and running into issues. I've created the tunnel successfully (verified by telnet). When I try to login with the command:

mysql --host= -P 3302 -u fakeuser -p

I get

Access denied for user 'fakeuser'@''

The issue is the @ I believe I need that to be fakeuser@localhost. Since I'm connected through the SSH tunnel why isn't it being set to localhost? How do I force it to localhost? where is it getting the from?

Note that I can't change any settings on the MySQL server.

Thanks for the help!

  • did you check that user with that host has privileges over that db?
    – jpganz18
    Jun 19, 2013 at 20:17
  • it does not have those privileges - I thought that was the point of the SSH tunnel, so it appeared to MySQL that the connection was coming from localhost (of the MySQL server) as opposed to the outside world
    – Scott W
    Jun 19, 2013 at 20:24
  • How did you set up the tunnel? (What options are you using to ssh?). If you specified ssh -L3302:remotehost:3306, then it's going to forward that port to the IP that resolves to 'remotehost'. Try -L3302:localhost:3306 or -L3302:
    – user143703
    Jun 19, 2013 at 22:40
  • I did -L3302: My problem is that when I do mysql --host= -P 3302 -u fakeuser -p, MySQL logs me in as 'fakeuser'@'', when only fakeuser@localhost has permission.
    – Scott W
    Jun 20, 2013 at 20:10
  • Okay, solved it. Apparently when setting up the SSH tunnel, I used localhost, instead of, which caused some issues when logging into MySQL.
    – Scott W
    Jun 20, 2013 at 21:58

1 Answer 1


When you do ssh tunnel it make a encrypted communication between your system to remote server and bind the remote opened port to your defined port.

ssh -L 33333:localhost:3306 fakeuser@server.remote.com

here 3306 as you said is mysql port no.

use IPADDRESS instead of localhost i.e

Connection to closed.
linux@tuxworld:~$ ssh -fNg -L 33333:localhost:3306 root@
root@'s password: 

See below eg which I did short while ago, mysql user is root and ssh user is also root. I opened a new terminal

linux@tuxworld:~$ mysql -u root -h -P 33333
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit

  • my problem is that when I do that, MySQL tries to log me in as 'fakeuser'@'', when I want it to login me in as localhost. I specify -h, yet it still logs me in as fakeuser@
    – Scott W
    Jun 20, 2013 at 20:09
  • ssh -L 33333:localhost:3306 fakeuser@server.remote.com did not work for me but ssh -L 33333: fakeuser@server.remote.com did
    – Scott W
    Jun 20, 2013 at 22:01
  • 1
    I have already mentioned. "use IPADDRESS instead of localhost i.e" . I think I should have to elaborate more. The actual mean as use .It seems your problem is solved. Jun 21, 2013 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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