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
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.
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.
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.
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.
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' => '', ),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With