Gurpreet Kaur
Gurpreet Kaur

Reputation: 77

Laravel shows error access denied for user

I am new to laravel and trying to run the migration but it showing me following error:

In Connection.php line 664:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from informati on_schema.tables where table_schema = test1 and table_name = migrations)

In Connector.php line 67:

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

Upvotes: 1

Views: 3626

Answers (3)

Cheran
Cheran

Reputation: 96

It's a database connection error.

Solutions:

If you are using a windows machine and XAMPP by default can use

 DB_CONNECTION=mysql 
 DB_HOST=localhost 
 DB_PORT=3306 
 DB_DATABASE=db_name
 DB_USERNAME=root 
 DB_PASSWORD=

If you are using a Linux machine and XAMPP by default can use also make sure the DB user has no password. Otherwise, you have to give DB password in .env

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=root
DB_PASSWORD=password

Don't forget to clear the cache using php artisan config:cache artisan command.(if you made any changes in env you have clear config cache)

Upvotes: 5

Udhav Sarvaiya
Udhav Sarvaiya

Reputation: 10061

In the .env file Just set up correct DB credentials:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username
DB_PASSWORD= // Your Database Password

DB_USERNAME should be set to root if you don't have a default username in the during installation of MySQL in XAMPP. If no password is set on the database, clear it DB_PASSWORD,

If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.

Also, After completion of .env edit, enter this command in your terminal for clear cache: php artisan config:cache

After you can be used run all of your outstanding migrations, execute the migrate Artisan command: php artisan migrate

Upvotes: 1

amit
amit

Reputation: 373

Check in your .env environment file. Set DB_Username to root and leave blank in DB_Password

DB_USERNAME=root
DB_PASSWORD=

If, you have same as above. Please clear cache with command:

php artisan cache:clear
php artisan route:clear

or, simply, go to app projectName>bootstrap>cache and delete all files inside it.

Sometime, this is seen because of the cache files. or incorrect DB username and passowrd.

Upvotes: 2

Related Questions