skip to Main Content

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


  1. Check and see if your mysql instance is running.

    Login or Signup to reply.
  2. first make sure that they are running and that the service related to MySQL is also running.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel
    DB_USERNAME=root
    DB_PASSWORD=123456
    

    Sample code for database connection settings in .env file.

    Your database connection username and password may be different and
    you should obtain these two items.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search