Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

前端 未结 24 1596
Happy的楠姐
Happy的楠姐 2021-02-03 19:23

I have installed Laravel 5 successfully and changed MySQL credentials in database.php file in config directory to \'

mysql\' => [
            \'driver\'           


        
相关标签:
24条回答
  • 2021-02-03 19:40

    Match the .env file and the config.php file with your username and password and your hostname in the database settings.if they are not equal,relation will not connect.

    0 讨论(0)
  • 2021-02-03 19:41

    Try to checkout the ".env" file in your root directory. It will be a hidden file. Correct these values.

     DB_HOST=localhost
     DB_DATABASE=homestead
     DB_USERNAME=homestead
     DB_PASSWORD=secret
    
    0 讨论(0)
  • 2021-02-03 19:41

    Instead of using this

    DB_HOST=localhost
    DB_DATABASE=wdcollect
    DB_USERNAME=root
    DB_PASSWORD=
    

    USE this

    DB_HOST=localhost
    DB_DATABASE=wdcollect
    DB_USERNAME=root
    DB_PASSWORD=''
    
    0 讨论(0)
  • 2021-02-03 19:42

    You need to run these two commands

    php artisan cache:clear
    php artisan config:cache
    
    0 讨论(0)
  • 2021-02-03 19:42

    Jeez! Thanks to umair.ashfr answer here below, I finally hit the nail with an issue that was eating my neurons.

    I had a password like DB_PASSWORD=ffjdh5#fgr on my .env, and MySQL connection was gracefully saying that "SQLSTATE[HY000] [1045] Access denied for user...", no matter what flavor of php artisan I was trying to run.

    The problem was that "#" sign inside the password. BEWARE! That means the start of a comment, thus my password was silently truncated! The solution is to declare password like DB_PASSWORD="ffjdh5#fgr"

    Regards

    0 讨论(0)
  • 2021-02-03 19:45

    None of these worked for me when I deployed my website online on shared hosting, below is what I did that worked.

    In the .env file, I changed

    DB_HOST=127.0.0.1
    

    to

    DB_HOST=localhost
    

    and viola, it worked well as expected.

    0 讨论(0)
提交回复
热议问题