1 year ago

Laravel - Access denied for user

Posted 1 year ago by george1


I have been trying to create a migration for my Laravel application and whenever I am doing to, by using the command php artisan migrate, I will always get the error:

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user '****'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = freeitemhuntDB and table_name = migrations and table_type = 'BASE TABLE')

  at /Users/georgeka/sites/freeitemhuntDB/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [1045] Access denied for user '***'@'localhost' (using password: YES)")

  2   PDO::__construct("mysql:host=;port=3306;dbname=freeitemhuntDB", "****", "****", [])

  Please use the argument -v to see more details.

I have looked at every piece on the internet, threads etc and most of the people would say, you have typed the wrong information in the .env file. However, mine are perfectly correct as I checked them over and over again.

I also read a post saying about that from MySQL 5.7 and up, root wont be allowed to be used as a username, hence I changed my mysql username to something completely different than root and the same thing happens.

I am using Laravel 5.8.17 and MySQL 8.0.13. When I built an application in Laravel 6 months ago, migration worked perfectly, but now it decided to not work at all!!

I cannot understand why everything has to be changing dramatically so I can get a million errors when I am restarting something after a while.

Is there anything else I could do to fix this error?

Please sign in or create an account to participate in this conversation.