0

I have installed lampp on a centos server that mysql server has been installed on. I removed mysql and I can access databases by this command on server:

/opt/lampp/bin/mysql -u username -p

When I want to access a database on this server by PDO in a php file, I receive this error:

 [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

I also removed var/lib/mysql directory. What is the solution?

Hedi
  • 322
  • 4
  • 17
  • @C0dekid.php I got this error before removing this directory. – Hedi Apr 11 '16 at 06:25
  • 1
    another solution would be: instead of using `localhost` use `127.0.0.1`. See here: http://stackoverflow.com/questions/4448467/cant-connect-to-local-mysql-server-through-socket-var-lib-mysql-mysql-sock – node_modules Apr 11 '16 at 06:27
  • After deleting the folder this will be next to impossible to diagnose. Could have been a selinux issue. Using TCP instead of sockets, as suggested, will solve the problem but will reduce performance (not much, but you should be aware of it). – Gerald Schneider Apr 11 '16 at 06:31
  • @C0dekid.php thanks a lot , it worked ;) – Hedi Apr 11 '16 at 06:34

0 Answers0