@lyiub is your file named .inv really? it should be .env.
SQLSTATE[HY000] [1045] Access denied for user 'DBname'@'localhost' (using password: YES) (SQL: select * from `users` where `id` = 9 limit 1)
I used laravel 5.4 with MAMP. My laravel project 5.4 working well on localhost and production. since 1 week I face this issue, I change some of the CSS and JS files in public, and I change the DB connection (in '.env' file) on my localhost to remote DB on live server, as following:
(.env)
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:D5EnjUeYst35NRdiDf3vfvSR4LQdf3ikfO2pKpp9tWHs=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=....................................rds.amazonaws.com
DB_PORT=.......
DB_DATABASE=DBname
DB_USERNAME=DBusername
DB_PASSWORD=DBpassword
It is stopped logged in and keep showing me this error:
(log file)
Next Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'DBusername'@'localhost' (using password: YES) (SQL: select * from `users` where `id` = 9 limit 1) in /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:647
Stack trace:
#0 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(607): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#1 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(326): Illuminate\Database\Connection->run('select * from `...', Array, Object(Closure))
#2 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1705): Illuminate\Database\Connection->select('select * from `...', Array, true)
#3 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1690): Illuminate\Database\Query\Builder->runSelect()
#4 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(462): Illuminate\Database\Query\Builder->get(Array)
#5 /Applications/MAMP/htdocs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(446): Illuminate\Database\Eloquent\Builder->getModels(Array)
...
...
#43 {main}
Just wondering, why it keep showing 'localhost in the error, while I change the DB connection in (.env) file to new remote DB (....................................rds.amazonaws.com) !!! if I change the username , it shows in the error that ( Access denied for user 'NewDBname'@'localhost' (using password: YES) .... etc ), and localhost keep not reflecting to the changes on new DBHOST.!
I check the remote DB, no any errors in tables or anything.
Note: It is stopped working suddenly on localhost and live server after changing to remote DB.
To figure out the problem, I tried to create new laravel project 5.4 and connect it with remote DB ,, it is working well and I can fetch the data from the remote DB. So only the current system keep showing me this error.
Appreciated for any suggestion of find what the error cause this issue
Please or to participate in this conversation.