Reputation: 2762
I am on a mac machine, i have problem to connect to the database, i try to connect it with the terminal it works pretty well, but when i run it i have always an error:
When i run my app for any query i have an error, example:
{"error":"SQLSTATE[HY000] [2002] No such file or directory (SQL: select count(*) as aggregate from `project` where `disabled` <> 1)"}
My .env file:
APP_NAME=linkedQare
APP_ENV=127.0.0.1
APP_KEY=base64:7JgSptYCl1RJ+AkY6WzQzbTLRply1rZIcf19rgvwvgQ=
APP_DEBUG=true
APP_URL=https://127.0.0.1:8000
VUE_URL=https://127.0.0.1:8080
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1:3306
DB_PORT=3306
DB_DATABASE=linkedQare
DB_USERNAME=root
DB_PASSWORD=root
I tried to change localhost to 127.0.0.1 but it doesn' t make any difference
I am using mysql 8 also, tried to uninstall, reinstall without any difference also
I think the connection to the database is not working as even if i change the database password, or remove it to try i get the same error message. when i run the command php artisan passport:install i have this error:
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
/Users/chu/Documents/linkedqare/linkedqare-laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=localhost;port=3306;dbname=linkedQare", "root", "root", [])
/Users/chu/Documents/linkedqare/linkedqare-laravel/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
My same app works pretty good in a windows machine
Upvotes: 2
Views: 248
Reputation: 2762
I finally found the answer, need to change the database.php file answer can be found here: PDOException SQLSTATE[HY000] [2002] No such file or directory
Upvotes: 0
Reputation: 914
The error message showing that MySQL connection via socket is tried. In the context of Laravel (artisan), you probably want to use a different environment.
Try changing APP_ENV=local
or
php artisan migrate --env=production
Another stackoverflow answer showing the same error with you.
Upvotes: 4