How to Connect to Database SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) - laravel

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

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

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

Related

No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6037]

No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6037] (View: C:\laragon\www\Project CRM\resources\views\users\index.blade.php)
keep getting the error in my laravel project , it only appears in my specific module of users and when i login with the user credentials , otherwise it does not affect my other modules of the code
my env file is
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=daybyday
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6037
any idea what is causing this error ?
thanks in advance
The redis server was not started and the port number was wrong in my env file

"SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' : Laravel [duplicate]

This question already has answers here:
lavaral 5 ERROR{ (SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)}
(2 answers)
Closed 4 years ago.
I am unable to register a user account in a Laravel project.
Error
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) (SQL: select count(*) as aggregate from `users` where `email` = xxx#xx.com)
Is there a solution?
Make sure that you update the below values in your .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=
Once updated .env file, stop the server of your project and serve the project again using the php artisan serve command.
You have to make changes in the .env file for the following fields:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME= your user name
DB_PASSWORD= your password

Laravel 5.3 production gey generate error failed to open stream

I've copied the example .env file on production server and made a .env with the following info (IP is fake numbers). I get an error when generating the app key saying PHP Warning: require(/var/www/laravel/bootstrap/../vendor/autoload.php): failed to open stream: No such file etc.
APP_ENV=production
APP_KEY=
APP_DEBUG=false
APP_LOG_LEVEL=error
APP_URL=http://108.99.999.99
DB_CONNECTION=mysql
DB_HOST=108.99.999.99
DB_PORT=3306
DB_DATABASE=npr
DB_USERNAME=root
DB_PASSWORD=mypasswordhere
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
You need to run composer install or composer dump-autoload.
As you don't have autoload.php file which is generated by composer.

DB_HOST and Browser Settings For Laravel App

I'm putting together a Laravel 5.2 application and using Homestead with it. When I need to migrate my database these are the settings that I have set up that allows me to do migrate. However if I want to use these in my browswer then I have to switch 127.0.0.1 to localhost. Why do I have to do this and how do I fix that?
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Anybody have any ideas on this?
if you are using wamp do like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=mysql
DB_USERNAME=root
DB_PASSWORD=
mysql is your database .you can access it by going localhost/phpmyadmin
I was able to find out that I need to keep it as DB_PORT=3306 and only use 33060 for when I'm trying to access the database with a program like Sequel Pro.

'PDOException' with message 'SQLSTATE [HY000] [1045]

i do not know why lately when I try to make a regitro in the database (using laravel), I get this error:
'PDOException' with message 'SQLSTATE [HY000] [1045] Access denied for user' homestead '#' localhost '( using password: YES) '.
.env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pruebas
DB_USERNAME=root
DB_PASSWORD=
in .env file is properly configured. What more could be ??
thanks.
the solution for this error, if everything is properly configured, is to restart the local server, in my case xampp

Resources