We can use a remote database server for Magento2 domains. In this, we use the Magento2 domain in one server and the database for this domain is configured in another one.
How to configure the Remote database server?
The remote MySQL database server must be installed with MySQL on it.
Then you need to configure the database and its user for the Magento2 domain.
For this, you have to log in to the Mysql prompt and create the DB.
mysql -u root -p
mysql > create database dbname;
mysql > GRANT ALL ON dbname.* TO dbuser@magento_server_ip_address IDENTIFIED BY 'password';
mysql > flush privileges;
mysql > GRANT ALL ON skynatsdb.* TO [email protected] IDENTIFIED BY 'Sky16R#k$kl';
Then try to connect this created database from the Magento2 server.
You have to log in to the Magento2 server first and then enter the below command to connect to the remote database server that we have created in the previous step.
mysql -u dbuser -h database_serverip -p dbname
Eg: mysql -u skynatsdb -h 192.168.10.1 -p skynatsuser
If you can successfully connect to the remote database from your Magento server. You can now proceed with changing the configuration file (env.php) of the Magento 2 domain to load with the new remote database. You can change the current default db section in the env.php file with the remote DB details.
'host' => '192.168.10.1'
'dbname' => 'skynatsdb'
'username' => 'skynats'
'password' => 'Sky16R#k$kl'
Now you can successfully access your Magento site with the Remote MySQL database server.
Nowadays handling Magento sites is a very complex and careful task for users, so it is important to set it up perfectly to handle the DB connection to the domain.
Our technical team with efficient experience in Magento Projects will help you to resolve any issue with your Magento domains.