1
votes

my code run fine in localhost but when i uploaded it on the serve following error show

Illuminate \ Database \ QueryException (1045) SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from rooms order by order_by asc) Previous exceptions SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (1045)

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:tT9jGFWVeBX5uLy/CVZbs8k+RNGBpMyJ526xfRv3DKQ=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=janatapa_shre
DB_USERNAME=janatapa_shre
DB_PASSWORD=Shre@123

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

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

though i have changed the database name , user and password in .env file it still says "Access denied for user 'root'@'localhost' (using password: NO)" which was my localhost password and user name''

I couldnt even clear my cache

while i was try to use following code on server

php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan view:clear

the following error was shown on the terminal

[In Connection.php line 664:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
sword: NO) (SQL: select * from rooms order by order_by asc)

In Connector.php line 70:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas
sword: NO) ]1

5
Try change APP_ENV to production and see what's happens.RomkaLTU
it isnt working. though i have changed the password to Shre@123 and user name to janatapa_shre error is showing SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO). I couldnt event clear the cacheAmrit Shrestha

5 Answers

7
votes

I also faced this issue, every thing is fine your DB_USERNAME or DB_PASSWORD, if you your password string contains # (for eg. Test123#) "feature"of 5.8 or above it treat # as comment delimiter, so rewrite your password as DB_PASSWORD='Test123#' and its works. it work for me.

2
votes

It's due to caching. so delete cache file 'config.php' from bootstrap/cache/config.php . Thanks

2
votes

I also was facing the same problem!
it's due to password string format. all passwords string contains # (for eg. Test123#. test@#, test123$$) must be between quotations laravel 5.8 above need password to be in a quat
DB_PASSWORD='Test123#' then run php artisan config:cache
then migrate DB through php artisan migrate it works for me just fine

0
votes

I have encountered the same error. SQLSTATE[HY000] [1045] Access denied for user 'niyo'@'localhost' (using password: NO)

I found that I did not create user called niyo and grant to him all privileges. I configured it in user accounts section of PhpMyAdmin interface.

.env file sample

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=oneagentdb
DB_USERNAME=niyo
DB_PASSWORD=123456
0
votes

When you make changes in .dev you must to this after this changes php artisan optimize