skip to Main Content

I run php artisan migrate, my basic migrations are taking a very long time. Then the database server is restarted and laravel returns an error SQLSTATE[HY000] [2002] Connection refused.

enter image description here

What could be the problem?

My .env db

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=laravel
DB_PASSWORD="passw#"

My config/database.php

    'default' => env('DB_CONNECTION', 'mysql'),

    ....

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        .....

MySql version

8.0.30-0ubuntu0.20.04.2 (Ubuntu)

mysql-logs

2022-09-06T08:06:01.880939Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30-0ubuntu0.20.04.2) starting as process 60463
2022-09-06T08:06:01.895767Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-09-06T08:06:02.442108Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-09-06T08:06:02.640013Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2022-09-06T08:06:02.667853Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2022-09-06T08:06:02.744622Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-09-06T08:06:02.744859Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-09-06T08:06:02.780189Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.30-0ubuntu0.20.04.2'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu).
2022-09-06T08:06:02.780471Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock

2

Answers


  1. Maybe your problem is on the connection port you are using, take a look at this threat, hope it helps PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

    Login or Signup to reply.
  2. there is no issue with the DB migrations are running but it is complaining due to an existing record on the failed jobs table,instead try this command and rerun the seeder again.

    php artisan migrate:refresh
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search