1

I am having problem while connecting php with mysql. Mysql server and client is running fine.And mysql socket file is in

/var/mysql/mysql.sock

But while connecting like :

$con = mysql_connect("localhost","root","pass");

It says

Socket operation on non-socket (trying to connect via unix:///var/mysql/mysql.sock)

Any clue?

DannyCruzeira
  • 564
  • 1
  • 6
  • 19
  • Answer to your issue: http://stackoverflow.com/a/9477985/1514026 – Dzhuneyt Aug 17 '12 at 14:32
  • 1
    Don't use mysql_* functions at all, instead use mysqli or PDO, as written in the [manual](http://php.net/manual/en/function.mysql-connect.php) – DannyCruzeira Aug 17 '12 at 14:36
  • possible duplicate of [MySQL is running without a socket file](http://stackoverflow.com/questions/9477552/mysql-is-running-without-a-socket-file) – Jürgen Thelen Aug 17 '12 at 15:10

2 Answers2

1

use

$con = mysql_connect("127.0.0.1","","");
mushfiq
  • 1,602
  • 2
  • 19
  • 35
  • Pointless if the server isn't configured to allow TCP connections, which most aren't, by default. – Marc B Aug 17 '12 at 14:54
0

It sounds like your actual MySQL Socket File is in a different location than where PHP is expecting it to be.

Do a phpinfo(); and see what the location of the socket file should be, per PHP.

You can then symlink it from where it is currently located.

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87