Laravel: SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost'

前端 未结 7 2074
北荒
北荒 2020-12-16 01:45

I just installed laravel and made a migration. But when i try to run it i get this error:

[PDOException]                                                              


        
相关标签:
7条回答
  • 2020-12-16 02:01

    Tried all the solutions here but no work for me

    This Worked on the first try:

    If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.

    I found this solution from here laravel.io (Read the solution of Byjml)

    0 讨论(0)
  • 2020-12-16 02:04

    I figured it out :) Had to chance the .env file :)

    Is there any changes in the schemaes?

    Shouldn't this work:

    public function up()
    {
        // Create table with columns
        Schema::create('users', function($table) {
            $table->increments('id');
            $table->string('username');
            $table->string(Hash::make('password'));
            $table->string('firstname');
            $table->string('lastname');
            $table->string('email')
            $table->string('role');
            $table->timestamps();
        }); 
    
    }
    
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Insert table to database
        Schema::drop('users');
    }
    
    0 讨论(0)
  • 2020-12-16 02:07

    Make changes in the database.php file in **config > local >database.php rather than change config > database.php file.

    hope it will work ;)

    0 讨论(0)
  • 2020-12-16 02:13

    Try to check out the ".env" file in your root directory. These values are taken first. Yours are just the defaults if there are none given in the .env file.

    DB_CONNECTION=mysql 
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=Your_Database_Name
    DB_USERNAME=Your_UserName
    DB_PASSWORD=Your_Password
    
    0 讨论(0)
  • 2020-12-16 02:16

    practically when you are using localhost server like xampp, you create the database manually "homestead", such errors are due to missing database arguments. 100% percent working test it and see

    hit your cmd and type in:

    create database homestead;  
    
    0 讨论(0)
  • 2020-12-16 02:17

    I tried to make changes to database.php file present within config folder it looks something like this

    'default' => 'mysql',
    ....
    ...
    'mysql' => [
                'driver'    => 'mysql',
                'host'      => env('DB_HOST', 'localhost'),
                'database'  => env('DB_DATABASE', 'sample'),
                'username'  => env('DB_USERNAME', 'root'),
                'password'  => env('DB_PASSWORD', ''),
                'charset'   => 'utf8',
                'collation' => 'utf8_unicode_ci',
                'prefix'    => '',
                'strict'    => false,
            ],
    

    I am not using any VM, I am using my local machine, with the database user as root and password a null.

    I have also changed my .env file and it looks something like this:

    APP_ENV=local
    APP_DEBUG=true
    APP_KEY=zLzPMzs5W4FNNuguTmbG8M0iFqhIVnsP
    
    DB_HOST=localhost
    DB_DATABASE=sample
    DB_USERNAME=root
    DB_PASSWORD=null
    
    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
    

    Even after doing all the changes when I try to register using the registration form that is shipped with laravel, I try to add a user to my database I get the following error

    After doing all the changes I cleared the cache and loaded it again and it seems to work for me now! if any one is also facing the same issue just run the following commands

    php artisan cache:clear
    php artisan config:cache
    
    0 讨论(0)
提交回复
热议问题