Can I make a MySQL socket file that points to a different machine?

Eric asked:

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?

My answer:


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 mysqltuner.pl 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.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.