Yes, it’s possible to connect this. It’s actually a really common way of structuring your servers. You have one server for your Web Requests and another for your Database.
The first and most important thing you need to do is allow access for VPS 1 on VPS 2(where your database is) on the port your database is listening on. Usually, MySQL/MariaDB use the port 3306.
To allow incoming MySQL connections from a specific IP address or subnet, specify the source. For example, if you want to allow the entire 18.104.22.168/24 subnet, run these commands:
sudo iptables -A INPUT -p tcp -s 22.214.171.124/24 --dport 3306 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 3306 -m conntrack --ctstate ESTABLISHED -j ACCEPT
The second command, which allows the outgoing traffic of established MySQL connections, is only necessary if the OUTPUT policy is not set to ACCEPT.
You’ll need to change the 126.96.36.199/24 with your actual IP address and run the above commands on the Database server.
Next, when you are with this, you should be able to connect with your credentials in your website to the database.