1
votes

I have installed XAMPP 1.6.2 (need this use this specific version) at /opt/lampp in Ubuntu 16.0.4. I have installed Mysql 5.7.18-0ubuntu0.16.04.1 using apt-get. I need to use the installed version of MySQL with PHP that came with XAMPP.

When I try to connect PHP with MySQL (independent installation), I get this error:

Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock'

I am still getting this error after trying the following things:

  1. Replaced all occurrences of '/opt/lampp/var/mysql/mysql.sock' with '/var/run/mysqld/mysqld.sock' in /opt/lampp directory.
  2. Restarted Apache, MySQL.
  3. Rebooted system.
  4. Searched on Stackoverflow, and tried existing solutions (eg. edit my.cnf)

Please help me out; Thanks.

1
is the mysql service running? - Florian Humblot
yes, i have tried to restart it as well. It didn't help - Lakshmikant Deshpande
are you able to connect using 127.0.0.1 instead of localhost for your connection? - Florian Humblot
when connecting to localhost, the socket connector is used, but when connecting to the IP address the TCP/IP connector is used. This could mean that the path to the socket is incorrect or that the socket is corrupted (the first case being more likely), try going to that path and seeing if it actually exists. - Florian Humblot
I checked that path, it does exist. Issue might have occurred due to incompatibility. Thanks. - Lakshmikant Deshpande

1 Answers

0
votes

I solved this issue simply by replacing localhost with 127.0.0.1 in my.cnf file.
As Fmashiro pointed out, this could have happened due to missing / corrupted socket file.