Under normal circumstances, your MySQL server may only allow applications to connect to it locally, meaning both are running on the same server. If, however, you run MySQL on a separate machine, you will need to configure it to permit remote connections.
(Note: Replace terms in italics with the correct information from your own server)
Step 1: Login to your server (either directly to the console or through SSH if the server is remote)
Step 2: Grant remote access to the MySQL database you want to use remotely:
$ mysql -u root -p mysql
mysql> update db set Host=’220.127.116.11‘ where db=’dbname‘;
mysql> update user set Host=’18.104.22.168‘ where user=’dbusername‘;
Alternatively, if you want to grant global access to all databases remotely:
mysql> GRANT ALL ON *.* to root@’22.214.171.124‘ IDENTIFIED BY ‘root-password‘;
mysql> FLUSH PRIVILEGES;
Step 3: Finally, you will need to open port 3306 on your firewall in order for the connections to go through. For a Linux iptables firewall rule:
# /sbin/iptables -A INPUT -i eth0 -p tcp –destination-port 3306 -j ACCEPT
And then save the changes:
# service iptables save
You should now be able to remotely connect to your MySQL server from your web application server without any problems.