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

﹥>﹥吖頭↗ 提交于 2020-06-17 09:14:10

问题


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


回答1:


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:


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




回答3:


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



回答4:


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



来源:https://stackoverflow.com/questions/60364671/sqlstatehy000-1045-access-denied-for-user-rootlocalhost-using-password

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!