0

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

1
  • MySQL is running? in your 192.168.1.172
    – Bojjaiah
    Apr 14, 2021 at 8:24

2 Answers 2

0

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.

0

The error message "SQLSTATE[HY000] [2002] Connection refused" typically means that the database server is not allowing a connection from your application. Here are some steps you can take to troubleshoot this issue:

  1. Check if the MySQL server is running on the host machine (192.168.1.172). You can do this by running the following command in the terminal of the host machine: systemctl status mysql.service

  2. Ensure that the MySQL server is configured to listen on the correct IP address and port. You can check this in the MySQL configuration file (usually located at /etc/mysql/my.cnf or /etc/my.cnf) under the [mysqld] section. Look for the bind-address directive. It should be set to the IP address of the server or 0.0.0.0 to listen on all IP addresses.

  3. Check if the MySQL user (root in your case) has the necessary privileges to connect from the application server's IP address. You can do this by logging into the MySQL server and running the following command: SELECT user, host FROM mysql.user;

  4. Ensure that the firewall on the MySQL server is not blocking the connection. You can check this by running the following command on the MySQL server: sudo ufw status

  5. If the MySQL server is running on a different machine, ensure that the machine is reachable from the application server. You can check this by running the following command on the application server: ping 192.168.1.172

  6. If all the above checks pass, try to connect to the MySQL server from the application server using the MySQL client to see if the connection details are correct. You can do this by running the following command on the application server: mysql -h 192.168.1.172 -u root -p

Remember to replace the IP address, username, and password with your actual values.

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.