For the MySQL database setup for Magento2, we can use a remote database server. In this setup, the Magento2 domain resides on one server, while the database is configured on a separate server.
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
password :
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.
vim /var/www/user/app/etc/env.php
----------------------------------
'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.
Handling Magento sites has become a complex and meticulous task for users today. Therefore, a proper MySQL database setup for Magento2 is essential to ensure a smooth connection between the database and the domain.
Our technical team with efficient experience in Magento Projects will help you to resolve any issue with your Magento domains.