0
votes

I am getting this error when i run (I am using laravel 7.9.2)

php artisan migrate
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = mydb and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675|

      +34 vendor frames
  35  artisan:37

Everything runs smoothly in the local environment

tried

php artisan config:cache
php artisan cache:clear

I can access the production database without any issue

My .env file should be good ( I am using other laravel versions in production and i haven't experienced any such issue)

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=mypassword

Note : I have upgraded the php version to 7.4.5

3
Could you verify whether the database credentials provided is .env file is correct? - sn n
please try php artisan optimize:clear - Christophe Hubert
Is this your production env file? Check your server ip this is localhost. - pr1nc3
@sn n database credentials are correct , i am able to use the same and login to the database through mysql workbench + through the shell - zaster
@ChristopheHubert tried that still not working - zaster

3 Answers

3
votes

Just only change .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1 or IP address
DB_PORT=3306
DB_DATABASE='your database name'
DB_USERNAME='your username'
DB_PASSWORD='your password'

it works for me!

0
votes

My database password was wrong

I was confused between the Database Connection Password and Database Password

Solved!

0
votes

I found the cause of the error and 90% of you will solve the problem in this way. I changed the port from mysqlin .ini file to 3306 to 4306 because mysql doesn't work, but I didn't specify it in .env file. then after changing the port in the .env file to 4306, we write the code "php artisan config: cache" to the terminal and then migrate. I hope this will help you!