The four causes for "No connection could be made because the target machine actively refused it" in mariaDB or mySQL
The scenario is you trying to connect to mysql on another remote server IP. The machine is refusing to even connect you.
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in U:\Webpages\yipp.ca\app\src\db.inc.php:28 Stack trace: #0 U:\Webpages\yipp.ca\app\src\db.inc.php(28): PDO->__construct('mysql:host=37.2...', 'yipp', 'hPKcxOvXnwvPX5R...') #1 U:\Webpages\yipp.ca\app\src\db.inc.php(38): getDB() #2 U:\Webpages\yipp.ca\app\src\routes.php(27): require_once('U:\\Webpages\\yip...') #3 U:\Webpages\yipp.ca\app\public_html\index.php(28): require('U:\\Webpages\\yip...') #4 {main} thrown in U:\Webpages\yipp.ca\app\src\db.inc.php on line 28
Check the causes & solutions below.
Reason #1
mariaDB or mySQL is not listening on the public IP but only on localhost.
Put the public IP of the server in /etc/mysql/mariadb.conf.d/50-server.cnf at the line "bind-address".
For example if your server IP is 123.123.123.123:
(...) # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 123.123.123.13
Some people like putting 0.0.0.0 there which will require less editing and downtime if your IP changes or you migrate to another server/IP.
Reason #2
You are connecting to the wrong server IP. Your server IP might have changed. Or if using the hostname, make sure the hostname resolves to the right IP. Try pinging it to see the IP it resolves to.
Reason #3
The SQL user you are trying to reach doesn't have permission to login from your client IP.
Usually mySQL or mariaDB will block any connection from a remote IP for a user unless the user@yourip is whitelisted.
This whitelisting is done directly in the users table in SQL.
Reason #4
iptables or other firewall are actively blocking the connection. Disable temporarily the firewall to test if this is the case. Note that there could be multiple reasons at once. Before trying this, make sure reasons 1 to 3 are not happening.
Recent Comments