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.

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

2 Answers 2

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 "127.0.0.1".

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

 bind-address            = 127.0.0.1

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 = 127.0.0.1 has come as default. It's a great lesson though! Thanks David and pQd! –  kavoir.com Sep 7 '09 at 7:20

skip-networking should do the trick.

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.