0

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!

4

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.

  • 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! – datasn.io Sep 7 '09 at 7:20
1

skip-networking should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.