Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm having trouble accessing a remote mysql server (that is set to skip-networking/no remote connections). I've been able to successfully create a ssh tunnel, but how can I access the server's mysql socket over that tunnel?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You'll need to have some kind of IP method to access that mysql server remotely, using only sockets will give you access to that mysql server from the local machine.

Your best option here would be activating networking but firewalling the mysql server so it's only accessible from localhost, then once you get your tunnel working it should be fairly straightforward to connect remotely through the ssh tunnel either directly from the command line ssh -L 3306:localhost:3306 user@server or using .ssh/config LocalForward 3306 localhost:3306

share|improve this answer
    
This is a great answer, unfortunately the server is out of my control and I can't turn on networking :( –  christo16 Jan 28 '11 at 11:22
    
Then another option you have (howeever a bit painful) is to use ssh to remotely execute mysql client and return the info to you, as said, not comfortable at all but it works ssh user@server 'mysql -Bs -uMYSQL_USER -pMYSQL_PASSWORD DATABASE -e "select * from blahblah;" –  lynxman Jan 28 '11 at 11:29
    
Ouch, I've asked the sysadmin if we can turn on network connections, crosses fingers –  christo16 Jan 28 '11 at 12:05
    
I think that if you ask him just to allow connections from localhost he'll be happy to comply –  lynxman Jan 28 '11 at 12:11
    
No - see answer below –  symcbean Jan 28 '11 at 12:32

If the mysql server is configured to allow no network connections, then its will only talk to programs connecting via the file socket. You've created a pipe which ends at a network socket - you need to create a bridge listening on the network port and connecting to the file socket.

I believe it's possible to do this with netcat - something like.....

nc -U -l 3306 /var/lib/mysql/mysql.sock

...but do RTFM and experiment.

share|improve this answer

@Lynxman, when mysql is running with --skip-network option you can not connect using TCP because it is not listening on 3306 port and connection can be made only using sockets.

http://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_skip-networking

symcbean@

Netcat wouldn't do the trick. From the manual this is what I found.

Create and listen on a Unix Domain Socket:
$ nc -lU /var/tmp/dsocket

share|improve this answer

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.