Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to access a MySQL database on a remote machine. I do not have user access to the machine that the server is running on, but I do have access to another remote machine on the same network.

  • The database is listening on localhost:3306 on machine S.
  • I wish to access that machine through machine C, from my laptop L.
  • I do not have ssh access to S but I do to C.
  • The database is not accessible from outside the local network of C and S.
  • I do not have root access to either S or C

In a similar question, the user has ssh access to the MySQL machine, whereas I do not.

Is this possible?

Thanks

share|improve this question
    
Can you successfully connect to S using a mysql client on C? –  heavyd Feb 8 '13 at 15:34
    
@heavyd yes I can access S from C using a mysql client (mysql -h S works) –  Simon Walker Feb 8 '13 at 15:39
    
If you don't have ssh access to S from C then what you want is not possible. Of course based on configuration of the database no outside access is not allowed at all so unlikely what you want is possible with your configuration. –  Ramhound Feb 8 '13 at 16:01

1 Answer 1

up vote 1 down vote accepted

You should be able to access MySQL using port forwarding on machine C. When you connect to C use a command like this:

ssh -L 3306:S:3306 username@C

That will setup a local socket that is listening on port 3306 (you may need to select a different local port if that one is already in use) which is being forwarded to the MySQL port on S. You should then be able to connect your local MySQL client to localhost:

mysql -h localhost
share|improve this answer
    
This works, thank you very much! I'm so used to using localhost in the tunnel command it never occurred to me to have anything else there! I did have a problem that using localhost tried to use a local socket file, so I switched to 127.0.0.1 and it worked. Thanks –  Simon Walker Feb 8 '13 at 16:04

Your Answer

 
discard

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.