Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a MySQL tuning script that in turn uses the socket (.sock) file on the local drive to connect to MySQL. Even though I have a copy of MySQL on this server, however, the MySQL that I want to work with is actually on a different machine-- in my normal app, the DB_HOST is a different IP address, etc.

So... is there a way to create a socket file that points to a remote MySQL server, that lives on a different IP?

share|improve this question
What, exactly, are you attempting to achieve? – ceejayoz Feb 13 '13 at 22:45
Do you mean that you are trying to run either mysqltuner or primer or something similar and have it connect to a remote mysql server? – Tom Geee Feb 13 '13 at 22:51
Yep-- I'm trying to run and it doesn't seem to have an option to connect to a remote server, only to use a socket file. – Eric Feb 14 '13 at 5:02
BTW why the downvotes? This seems like a legit, straightforward non-dupe question that contributes knowledge to the community. :-\ – Eric Feb 14 '13 at 5:03
Joel-- thank you for the feedback. I've got mysqltuner working fine, and in this case, I also want to try tuning-primer. I use both of the scripts to get a "second opinion" about the changes I make to my.cnf. Thank you for your comment that I should "learn [my] database workload and what the my.cnf settings do." I agree that these scripts are no replacement for knowing what I'm doing, but I think that they have their place. Which is why I asked my original question... so here we are back at the start. If you know the answer to my question I'd love for you to add it. Thanks. – Eric Feb 14 '13 at 17:40
up vote 6 down vote accepted

Yes, we call them network connections. Everything you do on the Internet uses them.

Aside from the AF_UNIX socket you are referring to, there are AF_INET sockets and AF_INET6 sockets, which make IPv4 and IPv6 connections, respectively. There are a few other types, but you probably don't care about ancient things like AppleTalk...

Unlike Unix sockets, network sockets do not have corresponding files on the filesystem. They can only be created in application code using the socket API (see the socket(7) man page).

In the case of the tuning scripts, they should have command line options that allow you to specify the remote host to connect to. The popular script, for instance, accepts --host and --port to specify a remote host. (Though specifying the port isn't necessary unless you moved it from the default of 3306).

You still need a username and password with USAGE privileges on the MySQL server, and the firewall must permit you access.

share|improve this answer

So... is there a way to create a socket file that points to a different IP?

socat - Multipurpose relay:

share|improve this answer

The 'socat' answer above will do what you want, but you're better off using the native TCP functionality rather than trying to redirect a UNIX socket, which is designed for high-performance IPC on a single local machine.

To compare, using TCP is like picking up the phone and calling someone, whereas a redirected socket is more like asking a friend to pick up the phone and call them, handing written notes to each other every time something is said. It's unnecessary complication.

share|improve this answer
I hear ya, but like I wrote in my question, I'm using a script that needs a socket. If it were my own code, I might go about it differently-- perhaps exactly as you describe. :-) – Eric Feb 14 '13 at 5:04

Your Answer


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.