Home > other >  How to Connect to Database SQLSTATE[HY000] [1045] Access denied for user 'root'@'loca
How to Connect to Database SQLSTATE[HY000] [1045] Access denied for user 'root'@'loca

Time:04-23

I got this error when i tried to connect to my database:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select active_template from general_settings limit 1)

I'm new to laravel so i'm sorry if it's a common question because i try to find the solution and see similar problems but not exactly the same.

I tried to change my .env files and use no pass for the db and restart the server but it is still getting the same error. Here's what my env files look like:

APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:xxx
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database123
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

what should i do? thankyou

CodePudding user response:

Try to make another MySQL user, and grant all privileges to ONLY that database. Mostly root user is denied from shared hosting since i check your APP_ENV is on production.

Hope this helpful

https://phoenixnap.com/kb/how-to-create-new-mysql-user-account-grant-privileges

CodePudding user response:

try php artisan config:cache and php artisan cache:clear after changing your .env file

  • Related