Access Denied for Database although credentials are correct

Posted April 25, 2021 505 views

As I was following this tutorial,

Everything is perfectly done except the database connection. During deploy, at migrate stage, it seems the env credentials provided is not able to establish a connection with the server itself.

  • Laravel 8
  • MySQL 8
  • PHP 7.4
  • Ubuntu 20 These are the specs

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @risingsoul1991,

Can you try using the following command to see if you would be able to connect to the database :

mysql -u laravel_db_user -p laravel_db -h localhost

You’ll need to change laraveldbuser and laravel_db with the actual information of course.

If it doesn’t work, most probably your password is not correct. To change it, you can use the following

ALTER USER 'laravel_db_user '@'localhost' IDENTIFIED BY 'New-Password-Here';


  • I got it through. It not the credentials problem but found out that the user I created don’t have the GRANT on the database. Just give the PRIVILEGE then it solved. Thanks!

    • Hi @risingsoul1991,

      I’m glad to hear you were able to resolve the issue and thank you for sharing the solution!

      Please feel free to use the community whenever you have any tech issues, we are here to help.