I have entered all values into files .env and database.php properly but I get this error:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from companies
)
This is file data
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:my key
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=username
DB_PASSWORD=mypass
I have entered the same data from
.env to database.php
like this:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'dbname'),
'username' => env('DB_USERNAME', 'username'),
'password' => env('DB_PASSWORD', 'mypass'),
'unix_socket' => env('DB_SOCKET', ''),
I have tried to change DB_HOST from 127.0.0.1 to localhost, and I get this error:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from companies
)
The problem is that the server does not support command prompt.
2
Answers
Check and see if your mysql instance is running.
first make sure that they are running and that the service related to MySQL is also running.
Sample code for database connection settings in .env file.
The next step is to perform migrations to create database tables
run
php artisan migrate
If you get an error again, there is a possibility that your MySQL service is not working properly or the port associated(3306) with it is a different number.