You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 5.4中.env配置无效,执行php artisan migrate报错求助

Fixing Laravel 5.4 Migration Access Denied Error

Hey there, let's troubleshoot this 1045 Access Denied error you're hitting when running php artisan migrate. The error message clearly shows Laravel is trying to connect to MySQL with an empty username, which points to issues with your .env configuration not being applied correctly. Here's how to fix it step by step:

1. Fill in the Missing Database Name

Your .env has an empty DB_DATABASE= value, but the error references table_schema = atp_db—so that's likely the database you intended to use. Update the line in your .env file to:

DB_DATABASE=atp_db

2. Clear Config Cache (Critical Step!)

Laravel sometimes caches configuration values, which might be causing it to ignore your updated .env. Run this command to clear the cache:

php artisan config:clear

3. Verify Your Database Credentials & Connection

  • First, confirm the root user can connect to MySQL without a password. Test this directly via the terminal:

    mysql -u root
    

    If this fails, you'll need to either set a password for the root user (and update DB_PASSWORD in .env to match) or adjust MySQL's user permissions to allow root access without a password from localhost.

  • Also, make sure the atp_db database actually exists in MySQL. If it doesn't, create it with this command:

    mysql -u root -e "CREATE DATABASE atp_db;"
    

4. Double-Check config/database.php

Ensure your MySQL connection in config/database.php is correctly pulling values from .env—it should look like this:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', '127.0.0.1'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', ''),
    'username' => env('DB_USERNAME', ''),
    'password' => env('DB_PASSWORD', ''),
    // ... other default configs
],

If there are hardcoded values here instead of env() calls, they'll override your .env settings.

Once you've completed these steps, run php artisan migrate again—it should connect to your database successfully and run the migrations.

内容的提问来源于stack exchange,提问作者Najib jamshidi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:38:11