Back to Error Center
Access denied for user
Error Message
SQLSTATE[28000]: Access denied for user 'root'@'localhost'
Cause
The database credentials in .env don't match the actual database user's permissions, or the user doesn't exist.
Solution
Verify DB_USERNAME and DB_PASSWORD in .env. Grant the user proper permissions in MySQL. Reset the MySQL root password if needed.
Code Example
Fix
# Check MySQL user permissions
mysql -u root -p
SHOW GRANTS FOR 'root'@'localhost';
# Grant permissions
GRANT ALL PRIVILEGES ON laravel_app.* TO 'root'@'localhost';
FLUSH PRIVILEGES;
# .env
DB_USERNAME=root
DB_PASSWORD=your_password
Debugging Steps
- Verify DB_USERNAME and DB_PASSWORD in .env
- Test the credentials with a MySQL client
- Check the user's permissions on the database
- Ensure the user has the correct host permissions
Prevention
Use separate database users for different environments. Grant minimum required permissions. Store credentials securely outside version control.