PDOException (1044) SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'
Put a .env
file in your root directory and paste this code there.
APP_ENV=local
APP_DEBUG=true
APP_KEY=1CaND3OKKvOGSBAlCg6IyrRmTQWwZjOO
DB_HOST = localhost
DB_DATABASE = YOUR_DATABASE_NAME
DB_USERNAME = USER_NAME
DB_PASSWORD = PASSWORD
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
Update your database, username and password field here and it should solve your problem. In your configuration file env()
function is looking for this file and variables from here.
UPDATE: You must create a blank database before running the app or migration.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=YOUR_DATABASE_NAME
DB_USERNAME=root
DB_PASSWORD=
The DB_USERNAME=
should be set to root
if you do not have a default username in the installation of MySQL in XAMPP.
We forgot to set DB_USERNAME=
in the .env file, so we got this error:
SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'
Open the .env file and edit it. Just set up correct DB credentials:
DB_USERNAME= //Your Database Username
DB_USERNAME
should be set to root
if you do not have a default username in the installation time
After changes of .env enter this command in your terminal for clear cache:php artisan config:cache
NOTE: If there is still error
If you are using the PHP's default web server (eg. php artisan serve
) you need to restart your server
OR
If you have used XAMPP then restart your Apache server