1
votes

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)

3
check .env fileJ. Doe
The error means that you don't have valid connection to your database. Have you created a database for your project? In your .env file do you use the correct credentials to make the connection?nakov
update .env files to vaild databse name and username and passwordManojKiran Appathurai
Check your database credentials properly in .env file.Muhammad Rizwan

3 Answers

5
votes

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)

1
votes

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.

1
votes

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