I am getting the following error when running the php bin/magento setup:upgrade command in my Magento 2.3 instance:

SQLSTATE[HY000] [2002] Connection refused

I can connect to the database using the mysql -u root -p and can run commands there without any issue. So I've determined that this is an issue with Magento's connection to the DB. I have gone in and changed the env.php setting from localhost to with no luck. Recently we did have a DNS change, but I'm not sure if that would effect the database. Are there any other solutions?

2 Answers 2


Check your env.php file if your db credentials are correct. Check if dbname has the right database that you are using, username and password are the ones you use to log into MYSQL.I would suggest you keep 'host' => 'localhost'.

  • All of the DB creds are correct. The site is functioning properly with the exception of that setup:upgrade command.
    – Petey88
    Oct 5, 2020 at 18:16
  • Then check your permissions for your magento installation, probably something is misconfigured. Oct 5, 2020 at 18:20
  • I have checked permissions and they are set correctly. Where else should I look?
    – Petey88
    Oct 5, 2020 at 18:32

Running the php bin/setup:config:set fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.