Access denied for user 'homestead'@'localhost' (using password: YES)

前端 未结 29 1533
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 10:23

I\'m on a Mac OS Yosemite using Laravel 5.0.

While in my local environment, I run php artisan migrate I keep getting :

相关标签:
29条回答
  • 2020-11-27 10:23

    in my case, after restarting my server the problem was gone.

    exit/close the "php artisan serve" command and

    re-run the command "php artisan serve" command.

    0 讨论(0)
  • 2020-11-27 10:25

    after config db restart the:

     php artisan serve
    

    If the serve is active before set db config.

    0 讨论(0)
  • 2020-11-27 10:28

    Two way to solve it

    First way (Not recommended)

    Open your database config file (laravel_root/config/database.php) & search for the below code block.

            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'blog'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', ''),
    

    Change the code block as below

            'host'      => 'yourHostName',
            'database'  => 'YourDatabastName',
            'username'  => 'YoutDatabaseUsername',
            'password'  => 'YourDatabasePassword',
    

    Second way (Recommended by Laravel)

    Check your Laravel root there have a file call .env if not exist, look for .env.example, copy/rename it as .env after that the file looks blow !

    APP_ENV=local
    APP_DEBUG=true
    APP_KEY=someRandomNumber
    
    DB_HOST=localhost
    DB_DATABASE=homestead
    DB_USERNAME=homestead
    DB_PASSWORD=secret
    
    CACHE_DRIVER=file
    SESSION_DRIVER=file
    QUEUE_DRIVER=sync
    
    MAIL_DRIVER=smtp
    MAIL_HOST=mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    

    Modify the below block as follow

    DB_HOST=yourHostName
    DB_DATABASE=yourDatabaseName
    DB_USERNAME=yourDatabaseUsername
    DB_PASSWORD=youPassword
    

    Now it will work fine.

    0 讨论(0)
  • 2020-11-27 10:28

    Check your ".env" file in the root folder. is it correct?

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=homestead
    DB_USERNAME=homestead
    DB_PASSWORD=secret
    
    0 讨论(0)
  • 2020-11-27 10:30

    After change .env with the new configuration, you have to stop the server and run it again (php artisan serve). Cause laravel gets the environment when it's initialized the server. If you don't restart, you will change the .env asking yourself why the changes aren't taking place!!

    0 讨论(0)
  • 2020-11-27 10:31

    if you are using php artisan migrate NOT from vagrant box but from host machine then you must define inside the .env the ip of the box 192.168.10.10

    and obviously set permission to homestead user from your ip something like

    grant all privileges on *.* to 'homestead'@% identified by 'secret';
    

    in .env file

    DB_HOST=192.168.10.10
    DB_DATABASE=homestead
    DB_USERNAME=homestead
    
    0 讨论(0)
提交回复
热议问题