php artisan migrate - SQLSTATE[HY000] [1045] Access denied for user 'laravel'@'localhost'
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
If you are running into issues while attempting to use the php artisan migrate command and encountering the error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'laravel'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'laravel'@'localhost' (using password: NO)
You are not alone. This is a common error, and it can be fixed with the right adjustments.
To start, ensure you have configured your database connection details in the.env file properly. The following code snippet shows a correct example:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=yourpassword
Note that:
- TheDB_USERNAME is usually 'root' or the database user created during MySQL installation, but depending on your application setup, it could be different. Use the actual username you have set.
- The connection port defaults to 3306 in most installations. If yours is different, adjust this value.
- Passwords can be omitted if they are not required for database access. However, if you find your migration command still giving a password issue, ensure the correct password is entered.
Once you have double-checked your database configuration settings, move to reviewing the MySQL configurations.
In Ubuntu 16.04 (unlike Mac OS X), MySQL installation may not be configured with a specific database user. As a result, if you are using thelaravel user specified in your configuration files, this could cause the error. To resolve this issue, follow these steps:
1. Open your terminal and run the command: sudo mysql_secure_installation
2. Follow the prompts to set a root password for MySQL (if you haven't done so already).
3. When asked if you want to disable remote login, select 'Y' or 'y' to prevent direct database access from unauthorized users over the network.
4. Next, update the privileges using the command: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Now, with the proper database credentials and user privileges set correctly, you should be able to run your php artisan migrate command without issues. If the problem persists or you encounter another error, revisit your database configuration settings, MySQL configuration, or consider seeking help from Laravel community resources such as the official Laravel documentation and Laracasts videos.