Magento – Database connectivity issue in Magento 2.1

configurationdatabasemagento-2.1

I am trying to connect to Magento database of another system with the following configuration in app/etc/env.php

  array (
    'host' => '192.168.1.172',
    'dbname' => 'datacenter',
    'username' => 'root',
    'password' => 'root',
    'active' => '1',
  ),

But I keep getting the below error, is there anything I can do to fix it? Your inputs are much appreciated.

2 exception(s):
Exception #0 (Zend_Db_Adapter_Exception): SQLSTATE[HY000] [2002] Connection refused
Exception #1 (PDOException): SQLSTATE[HY000] [2002] Connection refused

Best Answer

You should have to allow mysql connection from remote user.

here your remote machine is your magento instances

Edit my.cnf/my.ini file changing bind-address parameter to:

bind-address = 0.0.0.0

Also, make that skip-networking parameter is not defined.

For Linux:

/etc/mysql/my.cnf Debian/Ubuntu

/etc/my.cnf CentOS/CloudLinux/RHEL

For Windows:

"%plesk_dir%\MySQL\my.ini" for Plesk databases(port 8306)

"%plesk_dir%\Databases\MySQL\my.ini" for Clients databases(port 3306)

After that, restart MySQL server.

Look more for detail

Magento Doc OR Plesk

hope this will work for you.

Related Topic