Connection refused SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Troubleshooting Connection Refused SQL Errors During Laravel Migrations
Body:
If you've encountered the error "SQLSTATE[HY000] [2002] Connection refused" while running php artisan migrate in your Laravel application, there could be several possible causes. In this blog post, we aim to guide you through different scenarios and provide solutions that will help you resolve such problems.
Checking Database Connection Settings
Firstly, ensure that the database information is properly configured in your Laravel project. Typically, it would be stored within the `.env` file or a .yml configuration file like `database.php`. Verify if theDB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD environment variables or their equivalent configuration settings are accurate.
Checking Database Connection Availability
If the database connection settings look correct, make sure that your server is running the relevant services like MySQL/MariaDB, PostgreSQL, or any other database management system. To verify this, open a Terminal and typeservice mysql status (for MySQL) or an equivalent for your chosen database solution. If the service is not running, start it using the relevant command: sudo /etc/init.d/mysql start (for MySQL).
Reviewing Laravel Application Configuration
If the previous steps don't help, verify that your application has been correctly configured for Laravel Artisan. Check the `bootstrap/app.php` file to ensure that the$app->configureServiceProviders() method is called. Additionally, review if your `config/app.php` configuration file includes the necessary service providers and aliases required for running migrations.
Checking Connection Timeout
If your Laravel application isn't able to establish a connection with the database, consider setting a higher timeout value for the connection attempt. You can modify this in the `config/database.php` configuration file by adjusting theconnections.pdo array and adding an entry for 'driver_options' with 'options'=>array('timeout'=>60). This will give Laravel additional time to initiate a connection before throwing the error.