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

My mysql server is installed on the localhost machine where my php scripts are stored. So is what they say right that it's safer to connect to mysql from php that is placed in the same server?

If so, how to configure mysql to be connected via sockets instead of localhost:3306? Thanks!

share|improve this question
up vote 4 down vote accepted

The MySQL client utilities and libraries will automatically connect via the unix socket, rather than via a TCP socket, if you connect to "localhost". You can force it to connection to localhost via TCP by using "".

The basic reasoning is to protect MySQL by not allowing access from the network. This can be achieved using

 bind-address            =

in your /etc/mysql/my.cnf file. This is just as secure as "skip-networking" but has the advantage that you don't have to worry about whether you're connecting via TCP or unix socket.

share|improve this answer
I checked my my.cnf and it seems bind-address = has come as default. It's a great lesson though! Thanks David and pQd! – Sep 7 '09 at 7:20

skip-networking should do the trick.

share|improve this answer

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.