How to fix Laravel 8 - "SQLSTATE[HY000] [1049] Unknown database"

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Fix Laravel 8 - Solving the "SQLSTATE[HY000] [1049] Unknown database" Error

As a senior developer, I’ve seen countless developers run into frustrating connection errors when setting up a new Laravel project. One of the most common roadblocks is the SQLSTATE[HY000] [1049] Unknown database error, especially when attempting to run migrations like php artisan migrate.

This error doesn't usually indicate a fault within the Laravel code itself; rather, it points to a fundamental issue in how your application is trying to communicate with the underlying MySQL or PostgreSQL database server. Don't worry, this is a very common configuration problem that we can solve systematically.

Here is a comprehensive guide on diagnosing and fixing this specific error.


Understanding the Error: What is Unknown database?

When Laravel executes commands like php artisan migrate, it attempts to establish a connection using the credentials stored in your .env file. The error message SQLSTATE[HY000] [1049] Unknown database 'verified_db' means that the MySQL server successfully received the connection request, but it could not find a database specifically named verified_db within that connection context.

In simple terms: The issue is almost always related to the database not existing or the connection parameters being incorrect, even if you think they are correct.

Step-by-Step Troubleshooting Guide

Since you mentioned you have configured your .env file, we need to look beyond just those settings and examine the entire connection chain. Follow these steps to pinpoint the root cause:

1. Verify Database Existence

The most frequent cause of this error is that the database specified in your configuration (e.g., verified_db) has not been created on the database server yet.

Action: Log into your MySQL management tool (like phpMyAdmin, MySQL Workbench, or the command line) and manually ensure that the database you are trying to connect to actually exists.

If you are using a standard setup, you might need to create it manually before running migrations:

CREATE DATABASE verified_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

2. Scrutinize Your .env File Credentials

Even if the database exists, an incorrect username or password can lead to confusing errors. Double-check every entry in your .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=verified_db  # Ensure this matches the actual database name you created!
DB_USERNAME=your_db_user
DB_PASSWORD=your_secure_password

Developer Tip: Pay close attention to typos, especially in DB_DATABASE. Even a single misplaced character will result in an "Unknown database" error. This emphasis on secure and correct configuration is central to good development practices, much like the principles taught by the team at laravelcompany.com.

3. Check Host Accessibility and Permissions

If the database exists but you still get this error, the problem might be network or permission-related:

  • Host Access: Ensure that DB_HOST (e.g., 127.0.0.1 or localhost) is correctly pointing to where your MySQL server is running. If you are using Docker, ensure the container networking is set up correctly.
  • User Permissions: The database user specified in your .env file (DB_USERNAME) must have explicit CREATE, SELECT, and DROP permissions on the target database. If the user only has limited privileges, it might fail when trying to access a non-existent structure.

Conclusion: A Solid Foundation for Development

The Unknown database error is a classic symptom of a misaligned environment setup rather than a bug in Laravel's migration system. By systematically checking whether the database exists, verifying your .env credentials character by character, and confirming host accessibility, you will resolve this issue quickly.

Remember, when dealing with external services like databases, always approach configuration as a layered system: application settings (.env), server settings (MySQL setup), and networking permissions. By mastering these checks, you ensure that your Laravel application has the solid foundation required to run smoothly. Happy coding!