MariaDB is an open-source relational database management system (RDBMS) that emerged as a fork of MySQL after concerns over its acquisition by Oracle.

Developed by the original creators of MySQL, MariaDB retains compatibility with MySQL while offering additional features and enhancements.

It supports ACID-compliant transactions, is known for its performance and scalability, and is widely used in various applications for managing and organizing structured data

As a community-driven project, MariaDB is committed to open-source principles, fostering collaboration, and providing a reliable and accessible database solution for developers and organizations.

This tutorial will explain how to install MariaDB on a Debian 12 server as a Master-Slave Replication configuration and verify that it is running and has a safe initial configuration

Here’s a step-by-step guide for setting up a MariaDB Master-Slave replication on Debian 12:

Prerequisites

  • Two Debian 12 servers, one for the Master and one for the Slave.
  • MariaDB installed on both servers.
  • SSH access to both servers.

Step 1: Configure the Master Server

  1. Edit the MariaDB configuration file on the Master server:
  1. Configure replication settings by adding or enabling the following under the [mysqld] section:
  • Replace your_database_ with the name of the database you want to replicate.
  1. Restart the MariaDB service on the Master:
  1. Create a replication user with the necessary permissions:

In the MariaDB shell, execute:

  • Replace replica_user and replica_password with your preferred username and password for replication.
  1. Get the Master status to record the current binary log position:
  • Note down the values of File and Position, as these will be needed for configuring the Slave.
  1. Allow the Slave server’s IP in the firewall settings if applicable:
  • Replace slave_server_ip with the IP address of your Slave server.

Step 2: Configure the Slave Server

  1. Edit the MariaDB configuration file on the Slave server:
  1. Configure replication settings by adding the following under the [mysqld] section:
  1. Restart the MariaDB service on the Slave:
  1. Set up the replication on the Slave server: Log into MariaDB on the Slave server:

In the MariaDB shell, execute:

  • Replace master_server_ip with the IP address of the Master server.
  • Replace replica_user and replica_password with the replication user credentials created on the Master.
  • Set MASTER_LOG_FILE and MASTER_LOG_POS based on the values recorded from the Master.
  1. Create the database that need to replicate as Slave:
    • your_database_1
    • your_database_2
  2. Start the Slave replication process:
  1. Verify the Slave status:

Look for the following indicators in the output:

  • Slave_IO_State: Waiting for master to send event
  • Slave_IO_Running: Yes
  • Slave_SQL_Running: Yes If both Slave_IO_Running and Slave_SQL_Running show Yes, the replication is working correctly.

Step 3: Test Replication

  1. On the Master server, create a test table or insert data into the your_database database:
  1. On the Slave server, verify if the data appears:

If the table and data are present, your replication is successfully set up.

Step 4: Enable Automatic Start on Boot

  1. Ensure MariaDB starts automatically on both servers:

Done, MariaDB Master-Slave replication setup is now complete!

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.