So today I decided my website would run faster if I moved our databases to a different server, so I did, you can see how I am connecting below:
final String driver = "com.mysql.jdbc.Driver";
final String url = "jdbc:mysql://external_ip_address_here:3306/dbname";
final String username = "user";
final String password = "pass";
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
This works fine when I am connecting to 127.0.0.1
/ localhost
, now I am getting this error:
java.net.ConnectException MESSAGE: Connection refused (Connection refused)
My MySQL server is running Ubuntu 18.04.
I added multiple firewall rules to try and allow all incoming connections to port 3306 - sudo ufw allow from any to any port 3306 proto tcp
& I tried iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
, still not working, when i port scan the network it shows port 3306 as closed
FIX 1: This fixed the connection refused error -
Step 1: edit file /etc/mysql/mysql.conf.d/mysqld.cnf
Step 2: remove line bind-address = 127.0.0.1