phpmysqllaravelxampp

php artisan migrate throws PDOException


I found other thread with the same issue however I didn't fix it. The doc says I should just uncomment the extension=php_pdo_mysql.dll line which I did. I'm running Windows with xampp and I'm trying to connect to the MySql db. However I get this error:

$ php artisan migrate
exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for  user 'homestead'@'localhost' (using password: YES)' in C:\xampp\htdocs\your-project-name\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:47

I modified the database.php file with the right MySql credentials so I don't how why I get an error saying I'm trying to connect with the homestead username since I don't use it. I eventually tried to use homestead but I also get an error related to the PDO extension when I try to install it


Solution

  • You must change .env File in Laravel Root Directory. Give proper credential and also make sure that given database name is exists in MYSQL.

    Then after modifying .env File , make changes to config/database.php here use env so that it will check for that variable in .env File.If not found then it will use 2nd parameter as value.

            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'laravel5'),
            'username'  => env('DB_USERNAME', 'root'),
            'password'  => env('DB_PASSWORD', 'ganesh'),