Joren Polfliet
Joren Polfliet

Reputation: 127

Laravel 5 - Database connection denied

We're making an application for school in which I made a form to add something to the database. I've been following the Laracast, but whenever I try to submit my form to add the contents to the database I get;

PDOException in Connector.php line 55: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

I can use the command php artisan migrate perfectly and it creates the tables. It's just on the application itself that it doesn't work.

Is there any way to solve this?

.env file

PP_ENV=local
APP_DEBUG=true
APP_KEY=Hp7smlDebYOhW04Xn70J0TWfySNI2iAG

DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=boost
DB_USERNAME=root
DB_PASSWORD=******

CACHE_DRIVER=file
SESSION_DRIVER=file

Upvotes: 0

Views: 4182

Answers (3)

Jorre
Jorre

Reputation: 17591

Did you copy-paste the file correctly or do you really have PP_ENV=local on your first line? That should definitely be APP_ENV=local in order to detect your local environment / also, is your password "root"? I'm not asking for your password, but need to know if you are using the default scotchbox password here. There is no reason to not use root/root in scotchbox

One other thing you can check is to see if laravel is detecting your local environment or not: put this in a controller somewhere and print the $environment variable. Are you getting "local" as a result? $environment = App::environment(); echo $environment;

Upvotes: 1

Gravy
Gravy

Reputation: 12465

Either your username / password combination is wrong, or you have not given the correct grants with the correct hosts to the root user in mysql.

If your username password combination is correct - log into mysql from the command line as root. Then apply the following:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'CHOOSE A PASSWORD';

Which allows the root user to have all privileges from any host. I would not recommend doing this in a production environment.

Also check your database.php matches your .env file

'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,
        ],

Upvotes: 1

sandeepsure
sandeepsure

Reputation: 1125

First you have to install mysql properly.

Make you DB configuration in local.env or the file having .env extension. You need to provide same configuration which you have provided in database.php file.

Upvotes: 0

Related Questions