-1

I got an error:

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = lar1 and table_name = migrations and table_type = 'BASE TABLE')

when I replace DB_HOST with localhost an error will appear

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = lar1 and table_name = migrations and table_type = 'BASE TABLE')

how to solve it?

here my code :

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:oZx2D46tQg+pkzmsQ87ZM+GPvM1D8KXzEuVQN22iPCM=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lar1
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=27b67366036449
MAIL_PASSWORD=746d4c1cce5a90
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
pandu
  • 1
  • 1

1 Answers1

0

In your .env file, change DB_HOST from 127.0.0.1 to localhost

and then

php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
Kaushik Thakkar
  • 344
  • 3
  • 10
  • Illuminate\Database\QueryException SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = lar1 and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:670 666| // If an exception occurs when attempting to run a query, we'll format the error 667| // message to include the bindings with SQL, which will make this exception a 668| // lot more helpful to the develope... – pandu Apr 13 '20 at 17:14
  • Use this code in your route and check database Connection First. use Illuminate\Database\Connection; Route::get('/', function () { // Test database connection try { DB::connection()->getPdo(); echo "Connected successfully to: " . DB::connection()->getDatabaseName(); } catch (\Exception $e) { die("Could not connect to the database. Please check your configuration. error:" . $e ); } return view('welcome'); }); – Kaushik Thakkar Apr 13 '20 at 17:19