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
Answers
My database password was wrong
I was confused between the Database Connection Password and Database Password
Solved!
Just only change
.env
file:it works for me!
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!