2

I'm setting up my project after restoring my macOS Mojave and getting an error. I install MySQL with homebrew.

I tried to change localhost to 127.0.0.1 but it didn't help me

This is my .env

  • DB_CONNECTION = mysql,
  • DB_HOST = localhost
  • DB_PORT = 3306
  • DB_DATABASE= example
  • DB_USERNAME=root
  • DB_PASSWORD=

This is an error message

1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] No such file or directory") /Documents/cleaning/example/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31

2 PDOException::("SQLSTATE[HY000] [2002] No such file or directory") /Documents/cleaning/example/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27

piet.t
  • 11,718
  • 21
  • 43
  • 52
  • 7
    Possible duplicate of [PDOException SQLSTATE\[HY000\] \[2002\] No such file or directory](https://stackoverflow.com/questions/20723803/pdoexception-sqlstatehy000-2002-no-such-file-or-directory) – dparoli Sep 02 '19 at 07:24
  • Not correct your config of .env file for database – dılo sürücü Sep 02 '19 at 13:05

2 Answers2

1

If not exist .env file ,create one from .env-example and in set declare database configs and run command If you not callin key:generate

php artisan key:generate

If you have been all,exec below command


php artisan config:cache

And try

php artisan migrate

If your still get error try localhost or http://127.0.0.1 ,edit it And again run below command

php artisan config:cache

Import -2002 error given error when user and password wrong to host

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28
-2
  1. Try 127.0.0.1 instead of localhost in your .env file.
  2. Run php artisan cache:clear
  3. php artisan migrate --env=production

Above steps works for me.