Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Laravel on a Mac php artisan migrate error: No such file or directory [duplicate]

  1. Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
  2. composer install
  3. php artisan migrate, got the following error:

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

NB: php -v is 5.5 and mysql -v is 5.5 from the terminal Here is part of my config/database.php

    'mysql' => array(         'driver'    => 'mysql',         'host'      => 'localhost',         'database'  => 'essays',         'username'  => 'root',         'password'  => 'root',         'charset'   => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix'    => '',     ), 

I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..

Edit: I added these three lines in my php.ini

mysql.default_socket = /var/run/mysqld/mysqld.sock  mysqli.default_socket = /var/run/mysqld/mysqld.sock  pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock 

I also added this symlink:

sudo mkdir /var/mysql cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock 

But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install then php artisan migrate

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

The mac version is 10.7.4

like image 466
Tim Truston Avatar asked Oct 20 '13 09:10

Tim Truston


People also ask

How do I run a migration file in Laravel?

IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh . IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate again. Also, you can try php artisan migrate --seed if you have any seeder.

Which command is used to create migrations in Laravel?

To create a new migration, you can run the make:migration Artisan command and that will bootstrap a new class on your Laravel application, in the database/migrations folder.

Where is migration file in Laravel?

The new migration will be placed in your database/migrations directory. Each migration file name contains a timestamp, which allows Laravel to determine the order of the migrations.

What is php artisan migrate?

php artisan migrate:fresh is used when we want a fresh or new installation of our database. It deletes all the existing tables of the database and runs the migrate command. php artisan migrate:refresh is a two in one command that executes the :rollback command and the migrate command.


1 Answers

If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.

'mysql' => array(         'driver'    => 'mysql',         'host'      => 'localhost',         'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',         'database'  => 'database',         'username'  => 'root',         'password'  => 'root',         'charset'   => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix'    => '',     ), 
like image 79
keithics Avatar answered Sep 28 '22 16:09

keithics