Alpha0_0's avatar

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from `users` where `email` = [email protected] limit 1)

Hello Everyone!! I am New to Laravel. Today I install Homestead. But i am having problem with register and login of laravel default. When i run homestead.dev and login it shows error but when i run with 127.0.0.1:8000 it runs fine. Can You please help me to sort this out. what i am missing?

0 likes
8 replies
sherwinmdev's avatar

@Alpha0_0 the error states that the username/password combo you're using to connect to the database is incorrect. check your .env file and see if the database credentials matches a database user that has access.

Alpha0_0's avatar

APP_NAME=Laravel APP_ENV=local APP_KEY=Key APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=root DB_PASSWORD=

Above is mine .env

I have made homestead db in xampp... what i am missing.. i am really confused with vagrant database and normal xampp database..

Cronix's avatar

is your 'homestead' database located within homestead, or is it on your host computer? (edit - you said you created it on xampp - read below)

homestead creates its own database on the homestead vm (not your host computer). If you leave the default .env settings alone, it should be able to connect to it using the default settings without any further alteration.

I have a feeling you created a homestead db on your local host computer, but laravel is trying to connect to the one on your homestead vm. In your .env, 127.0.0.1 refers to the homestead vm, not your host computer.

The default settings for homestead are:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

And homestead automatically creates a db named homestead, with user homestead and a password of secret during installation. So it should work out of the box.

devnote's avatar

Your .env file is proper, but stop the server the project and again run the project using the php artisan serve command.

devnote's avatar

@Sinnbeck Thank you, but other users getting same error. so my answer help them.

1 like

Please or to participate in this conversation.