Replication enables you to easily maintain multiple copies of MySQL data. It is achieved through the master container data being automatically copied to one or more slave databases.
Having your data stored within multiple database containers can be very helpful for improving performance, running backup services, analyzing information and alleviating system failures.
There can be highlighted the following use cases for MySQL replication implementation:
Scale-out solutions – improving performance by spreading the load across multiple slaves where all reads take place, while all writes and updates take place on the master database
Backups – running backups on the slave without affecting the master data
Analytics – creating live data on the master and analyzing it on the slave without impacting the master performance
Long-distance data distribution – making a local copy of data that will be used by a remote site without direct access to the master
Usually complex procedure of setting up MySQL master-slave replication is a completely automated process with Jelastic. To save your time and effort, we have developed a ready-to-go package with replication being already configured.
Now let’s take a look at the package structure and the step-by-step guide to get it easily deployed to the Cloud.
One-Click MySQL Cluster for Instant Deploy
The one-click installation package is built using the devbeta/mysql57:5.7.14-latest Docker image. By default, you get two MySQL 5.7 database containers – the master and the slave. You can adjust the exact number of slave containers during the package installation stage, or afterwards within the topology wizard – these procedures are described later in the article.
Within the package, each database container receives the default vertical scaling limit – from 1 reserved to 8 dynamic cloudlets (up to 1 GiB of RAM and 3.2 GHz of CPU). Subsequently, you can readjust the default resource allocation limit within the topology wizard at the dashboard.
Now, let’s proceed further to get MySQL Cluster package installed to the Cloud.
Replicated MySQL Databases Installation
The JPS package deployment is a completely automated process that can be accomplished in just a few clicks.
1. Log in to the Jelastic Platform with your credentials and click Import at the top pane.
2. Switch to the URL tab and insert the link from below to fetch the required manifest.jps file:
3. In the opened confirmation window, enter the total number of containers where one container is the master and the rest of containers are the slaves.
Type environment name and, optionally, Display Name (alias). Also, select the preferable region (if several are available) and click Install.
The environment installation and configuration will take a few minutes, and then you’ll see a frame displaying your master node administration data.
Now, let’s put the master database into action to check that replication works properly.
Testing the Installed MySQL DB Replication
To ensure that data is replicated to the slave databases even after horizontal scaling, we’ll create a new database in the master container, add one more MySQL slave node to the cluster, and check the data inside.
Creating a New Database
1. Click the Open in browser button next to the MySQL master node to launch the phpMyAdmin web interface.
2. Log in with the credentials that you’ve received via email upon the package installation.
Click Go to access the page.
3. Switch to the Databases tab, type a name for a new database (e.g. Jelastic) and click Create.
Now, when the database is created in the master node, let’s scale the environment out and then check the replicated data within the added slaves.
Adding a Slave
All the containers added after the cluster installation act as slaves with the corresponding master data replication automatically enabled. To adjust the number of slave containers, perform the following steps.
1. Click the Change environment topology button next to the target environment.
2. Scale containers by means of the +/- buttons in the middle section of the wizard.
Click Apply to save the settings.
Now, when you’ve adjusted the exact number of required slave containers, let’s launch the slave admin interface to check replication results.
To make sure that data replication from the master to the slave containers works as intended, perform the following steps.
1. Click the Open in browser button next to the target MySQL slave node to launch the phpMyAdmin web interface.
2. Log in admin interface (use the same login and password that you’ve received via email after the package installation).
In the same way, you can access the admin interface of the newly added slave to check the replicated data availability.
Once logged in, you can access and manage the database (Jelastic, in our example) that was earlier created in the master container.
That’s it! MySQL master-slave replication is up and running and the cluster is ready for data processing. Integrating database cluster to your project usually depends on application specifics, you can find various drivers and libraries at the official connectors page.
Try this solution for free at one of our cloud hosting providers platforms. Also, subscribe to our blog and learn about other useful solutions and recent news from Jelastic.
Still having some issues with MySQL master-slave replication setup? Feel free to ask for help within the comments below or get in touch with our technical experts at Stackoverflow.