Saturday, February 26, 2022

[FIXED] SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) . DB_HOST set to localhost

Issue

I moved the Laravel project from localhost to server. Which I have done every step on the server.

I am able to view the login page on my server. The problem is I am not able to connect with my MySQL server.

My .env file:

APP_NAME=Transport
APP_ENV=local
APP_KEY=base64:mrakeyidharhaikonsdf
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=transport_db
DB_USERNAME=root
DB_PASSWORD=mypass

I tried to change the host to 127.0.0.1 and also tried to put my server's IP address. It didn't helped me. Am I missing something?

My error:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select count(*) as aggregate from users where email = user.email@gmail.com)

I know this question may have answers already on Stack Overflow. But I have different issue here.


Solution

Make sure your database credentials and database host are set correctly:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"

If you have not set any database password then add:

DB_PASSWORD=""


Answered By - Rahul Gupta

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.