How to Setup Mariadb Replication tutorial. Data Replication is very crucial when it comes to protecting and ensuring high availability data and the ease of access during unexpected error like system crash, hardware or software-based error, etc. One of the data replication, MariaDB is a replication that can take place in various mechanisms that includes master-slave, master-master, and start and multi-source mechanism.
What is MariaDB?
MariaDB is the popular open-source Relational Database Management System (RDMS). It was designed by the original developer of MySQL as an alternative after businesses got concerned with the acquisition of MySQL by Oracle Corporations in 2009.
Â
MariaDB works by transforming data into a structured and organized form and gives support to multiple applications. It is the fastest, scalable, sturdy, and encompasses several plug-ins. Some of its significant users are Wikipedia, Google, WordPress.com, and a lot more.
How MariaDB Replication Works
With MariaDB, you can either replicate the entire database or select a subsequent amount of data from the database. MariaDB replication utilizes an enormous slave configuration and enables the binlog on the master server. This master server uses a global transaction ID to write every transaction to the binary log.
Â
With Global Transaction ID, you can effortlessly determine the same binlog on separate servers replicating each other. The binary log has all the records concerning the changes done in the database to both the data and structure. It also takes care of the time taken to execute each statement. Furthermore, slave servers read this binary log from the master server when the replication of data is required. It, as a whole, makes MariaDB an excellent data replication software.
Copying data from multiple databases is known as replication. The databases that are to be copied are known as master databases or servers. The replicated data might include multiple or single databases or data tables used from the desired database.
Â
The primary features of MariaDB Replication are:
Â
Scalability – When you have one or more slave servers, you can read data on them. It, thereby, reduces the load on the master server in which only accurate operations can be performed.
Data Analysis – You can effortlessly analyze data on the slave server, thereby reducing the burden on the master server when MariaDB replication is updated in place.
Backup Assistant – Backup Assistance allows you to replicate data, which can be used as backup data. This backup data further acts as stand-alone data in a stable state.
Distribution Of Data – When you have MariaDB replication in place, you tend to work locally on this data without even connecting to the master server. By connecting subsequently, you can merge the updated data with the master data.
In this post, we will show you how to set up MariaDB replication on Ubuntu 20.04.
First, you will need to install the MariaDB server package on both Master and Slave nodes. You can install it by running the following command:
apt-get install mariadb-server -y
After installing the MariaDB server, start the MariaDB server service and enable it to start after system reboot:
systemctl start mariadb
systemctl enable mariadb
Next, you will need to secure the MariaDB installation and set a MariaDB root password. You can do it by running the mysql_secure_installation script:
mysql_secure_installation
Answer all the questions as shown below:
Enter current password for root (enter for none): Enter
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Once you are finished, you can proceed to configure the Master node.
Step 2 - Prepare the Master Node
MariaDB server uses a binary log file to perform the replication. By default, the binary log is disabled in the MariaDB default configuration. So you will need to edit the MariaDB configuration file and enable the binary log.
nano /etc/mysql/mariadb.conf.d/50-server.cnf
First, change the bind-address from localhost to 0.0.0.0:
bind-address = 0.0.0.0
Next, add the following lines at the end of the file to enable the binary log:
Next, you will need to create a replication user on the Master node. The Slave node will use this user to connect to the Master server and request binary logs.
To create a replication user, connect to the MariaDB with the following command:
mysql -u root -p
Provide your MariaDB root password and hit Enter. Once you are connected, you should get the following shell:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1-log Ubuntu 20.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Next, create a replication user and set a password:
MariaDB [(none)]> CREATE USER 'replication'@'%' identified by 'securepassword';
Next, grant replication slave privilege to the user with the following command:
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%';
Next, flush the privileges to apply the changes:
MariaDB [(none)]> FLUSH PRIVILEGES;
Next, verify the Master status using the following command:
MariaDB [(none)]> SHOW MASTER STATUS;
You should get the binary log file name and position in the following output:
In the above guide, we explained how to set up MariaDB replication on Ubuntu 20.04 server. You can now implement this setup in the production environment to simplifies recovery upon one of the master nodes failures. MariaDB replication is the best backup solution to backup a database from one Master database server to one or more Slave servers.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
4.84votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Please login to comment
1 Comment
Most Voted
NewestOldest
Inline Feedbacks
View all comments
Yury Merzlikin
Member
1 year ago
Just remark. No more such script as mysql_secure_installation, it has new name in MariaDB: mysql-secure-installation
Just remark. No more such script as mysql_secure_installation, it has new name in MariaDB: mysql-secure-installation