Search code examples
laravelamazon-web-servicessshaccess-denied

[PDOException]- SQLSTATE[HY000] [1045] Access denied for user 'root'@'ip' (using password: YES)


I am trying to connect to AWS through ssh in order to migrate some files. I connected successfully using the following command:

ssh -i ~/Downloads/key.pem ec2-user@myuser

Then, I tried to run the following :

php artisan migrate

I got the following:

[PDOException]                                                               
  SQLSTATE[HY000] [1045] Access denied for user 'user'@'ip' (using password: YES)

What could be preventing me from accessing my DB in order to migrate?!


Solution

  • When you connect to AWS you're connecting to a unix shell account on a virtualize linux server via SSH.

    On this virtual server (or maybe another server), you're running an instance of a database application. This database application is also a server. However, it has its own credential system. When you see this error message

    [PDOException]
    SQLSTATE[HY000] [1045] Access denied for user 'user'@'ip' (using password: YES)

    This is PHP/Laravel telling you

    Hey, I tried to connect to the database with the credentials in my app/config/database.php file, but the server told me those credentials were invalid.

    In other words, the password you configured for "user" didn't match the actual password, or the "user" account isn't authorized to access the database service (MySQL?) from the IP address PHP is running.

    Use the correct database credentials, and your error will go away. Use the command line mysql program to test your database credentials.

    Hopefully that's enough to get you Google-ing for the right thing! :)