Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLSTATE[HY000] [2002] No such file or directory [duplicate]

Tags:

I am trying to run a laravel project on OS X. I installed MySql with homebrew. I tried googling around for why I'm getting this error:

SQLSTATE[HY000] [2002] No such file or directory 

when I try to do

php artisan migrate 

And most of the answers I see say php and MySql cannot communicate to each other. I've been trying to see where I went wrong since I think I followed previous posts about it, and it still doesn't work. I created a page that just does this:

<?php     phpinfo(); ?> 

And I see these types of things: In the Configure area, I see:

'--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--enable-pcntl' '--enable-zend-signals' '--enable-dtrace' 

loaded configuration file:

/usr/local/etc/php/5.4/php.ini 

If I ls /tmp, I do see mysql.sock.

In that php.ini file, I set these lines: pdo_mysql.default_socket=/tmp/mysql.sock mysql.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock

And then in /usr/local/Cellar/mysql/5.6.16/my.cnf, I added the following line:

socket = /tmp/mysql.sock 

I DID restart apache, as well as check mysql is running. I haven't seen any other advice besides the php and mysql connection. I think there are two versions of php on my system because when I installed mcrypt or something else I can't remember, it installed another php version. But when I do look at the output of phpinfo, I'm editing the appropriate php.ini file. I didn't know if there is another piece I am missing. Any thoughts? Thanks

like image 766
Crystal Avatar asked Mar 05 '14 03:03

Crystal


2 Answers

I had a similar error. I am using MAMP and what solved my issue was:

  1. creating a symbolic link in: /var/mysql (create the directory if it does not exist)
  2. cd /var/mysql && sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock
like image 113
HappyCoder Avatar answered Oct 03 '22 01:10

HappyCoder


For users which are looking for a solution on XAMPP (Tested and worked on Mac OS X),

Open terminal and create a symbolic link :

sudo mkdir /var/mysql cd /var/mysql sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock 
like image 39
F3L1X79 Avatar answered Oct 03 '22 01:10

F3L1X79