Error: MySQL - "No Connection Could Be Made" Due to Target Machine Refusal
When attempting to connect to a remote MySQL database, it's possible to encounter the error "No connection could be made because the target machine actively refused it." Despite encountering similar issues, the reasons can vary.
In this instance, the issue arises due to the configuration of the MySQL server. By default, MySQL may only accept connections from the *nix socket or for localhost only.
Solution:
To resolve this error, you need to modify the my.cnf configuration file located in /etc/mysql/my.cnf (for Ubuntu). Here's a breakdown of the changes to make:
1. Configure bind-address:
Uncomment the bind-address line and set it to 0.0.0.0 to allow connections from any IP address.
bind-address = 0.0.0.0
2. Disable skip-networking:**
Comment out the #skip-networking line to enable networking. This line is usually commented out by default.
#skip-networking
3. Restart MySQL:
Once the changes are made, restart MySQL to apply them. You can do this with the following command:
sudo systemctl restart mysql
Caution: Before making these changes, be aware that if the MySQL machine is accessible from the public Internet, it will become vulnerable to connections from any source. Ensure proper security measures are in place to prevent unauthorized access.
The above is the detailed content of MySQL Connection Refused: \'No connection could be made...\' - How to Fix?. For more information, please follow other related articles on the PHP Chinese website!