2

I am beginner in Laravel PHP framework.That's why i am trying basic task from HERE (Laravel.com) .I followed this basic task step by step.But after finishing this i am getting an error. I am putting the error here.

PDOException in C:\xampp\htdocs\quickstart\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

What is the meaning of this error?

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

Here is my .env file.

DB_HOST=localhost
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

I have found similar problem in here. But there is no proper solution of it.

Here i add few lines (48 to 63) from Connector.php .

public function createConnection($dsn, array $config, array $options)
{
    $username = Arr::get($config, 'username');

    $password = Arr::get($config, 'password');

    try {
        $pdo = new PDO($dsn, $username, $password, $options);
    } catch (Exception $e) {
        $pdo = $this->tryAgainIfCausedByLostConnection(
            $e, $dsn, $username, $password, $options
        );
    }

    return $pdo;
}

Really I do get right solution of it. Can anyone give me the right solution to it? BTW this is laravel 5.2.

2
  • Is your .env file readable/in the right position? because if it's not, Laravel will default to what's written in the config/database.php file. There's nothing wrong in your Connector.php, as the error clearly states Laravel's using some other kind of configs Commented Jan 12, 2016 at 10:20
  • i am also adding database details in config/database.php but it was not working. Commented Jan 12, 2016 at 10:23

3 Answers 3

1

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

This means, that your provided username and password is incorrect. If you're using homestead, default username ir homestead and the password is secret. Also, You might need to change the database port, since the default laravel configuration will look for port 3306, but homestead runs on port 33060

So the .env file should look like this:

DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PORT=33060

Source

Sign up to request clarification or add additional context in comments.

Comments

1

Try to remove this file in the directory:

bootstrap/cache/config.php

Or run this in the terminal:

php artisan config:clear
php artisan cache:clear

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

You need to install php module for pdo_mysql

to do that run this command on your server

yum install php-mysqlnd

Then restart httpd service

service httpd restart

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.