Let’s configure MySQL master-slave replication in order to protect your application from downtime or data loss.
MySQL in your environment with TYPO3 deployed will be used as a master database. For the slave database, you need to create a separate environment.
Navigate to the Jelastic dashboard and create your environment with MySQL node, which is going to be used as a slave database. Name your environment (e.g. slave-db) and click Create.
And now, let’s configure each database separately:
As we’ve mentioned above, we use MySQL in the environment with app deployed (i.e. typo-cluster) as our master database.
1. Click Config button for your master database.
server-id = 1log-bin = mysql-bin
2. Navigate to etc > my.cnf file and set the following properties as it is shown below (you just need to uncomment two lines):
We use binlog-format=mixed to allow a replication of operations with foreign keys.
|Do not use binlog_format =statement otherwise you will get errors later on!|
3. Save the changes and Restart MySQL in order to apply new configuration parameters.
4. Click the Open in browser button for master MySQL. Log in using credentials you have received via email when creating the environment.
5. Navigate to the Replication tab and click on Add slave replication user.
6. Specify the name and password for your slave replication user and click Go.
Your slave user is successfully created.
And now, let’s connect the master database with slave MySQL.
1. Click the Config button for your slave database.
server-id = 2slave-skip-errors = all
2. Navigate to my.cnf file and add the following strings:
We allow our slave base to skip all errors from master (slave-skip-errors = all) in order not to stop normal slave operation, in case of errors on the master base.
Skipping this step is not recommended at the development stage, in order to locate bugs, etc. However here, we focus on production, when your code has already been tested. Any error on the master's side can stop slave or lead to its unsynchronization. In this case, the error may be even innocuous. Some minor errors will probably occur on production, so the replication can be stopped because of small errors.
3. Save the changes and Restart your slave database server in order to apply the new configuration parameters.
4. Navigate to phpMyAdmin using the credentials which Jelastic sent you when you created the environment for your slave database.
5. Go to the Replication tab click configure for Slave replication.
6. Configure your master server (enter the name, password and host of your slave replication user).
Now your master server is configured.
7. Click on Control slave > Full start for the slave server, in order to run Slave SQL and Slave IO threads.
8. Check the slave status table to ensure that everything is ok.
The replication is configured and all the data is synchronized between the master and slave database.