1

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)

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Gurpreet Kaur
  • 77
  • 1
  • 3
  • 10
  • 2
    check .env file – J. Doe Feb 22 '19 at 09:46
  • 2
    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 Feb 22 '19 at 09:47
  • 1
    update .env files to vaild databse name and username and password – ManojKiran A Feb 22 '19 at 09:47
  • 1
    Check your database credentials properly in .env file. – Muhammad Rizwan Feb 22 '19 at 09:49
  • Yes, @navkov I have created a database with name test1 in phpmyadmin and edited the .env file as follow, please check : DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=test1 DB_USERNAME=root DB_PASSWORD= – Gurpreet Kaur Feb 22 '19 at 09:50
  • 1
    Possible duplicate of [MySQL Error: : 'Access denied for user 'root'@'localhost'](https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost) – Prathamesh Doke Feb 22 '19 at 09:52
  • after configuring your .env file run "php artisan config:cache" command in te=he console – Prathamesh Doke Feb 22 '19 at 09:53

3 Answers3

5

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)

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64
Cheran
  • 96
  • 5
1

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.

amit
  • 353
  • 1
  • 3
  • 19
1

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

Udhav Sarvaiya
  • 9,380
  • 13
  • 53
  • 64