0
0
MySQLquery~30 mins

Replication basics in MySQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Replication basics
📖 Scenario: You are managing a small online store database. To keep your data safe and available, you want to set up a simple replication system where one database server copies data from another.
🎯 Goal: Build a basic MySQL replication setup by creating a master database with a sample table, configuring replication user credentials, and setting up the slave to replicate data from the master.
📋 What You'll Learn
Create a sample database and table on the master server
Create a replication user with proper privileges
Configure the master server to log binary changes
Set up the slave server to connect and replicate from the master
💡 Why This Matters
🌍 Real World
Replication is used to keep copies of data synchronized across multiple servers for backup, load balancing, and high availability.
💼 Career
Database administrators and backend engineers often set up and maintain replication to ensure data safety and system reliability.
Progress0 / 4 steps
1
Create sample database and table on master
On the master MySQL server, create a database called store and inside it create a table called products with columns id (integer primary key) and name (varchar 50). Insert one row with id 1 and name 'Book'.
MySQL
Need a hint?

Use CREATE DATABASE to make the database, then CREATE TABLE for the products table. Insert a row with INSERT INTO.

2
Create replication user on master
On the master server, create a replication user called repl_user with password 'repl_pass'. Grant this user the REPLICATION SLAVE privilege.
MySQL
Need a hint?

Use CREATE USER with host '%' for any IP, then GRANT REPLICATION SLAVE privilege.

3
Configure master for binary logging
On the master server, enable binary logging by setting log_bin to mysql-bin and set a unique server ID 1. This is done in the MySQL configuration file (my.cnf or my.ini).
MySQL
Need a hint?

Binary logging and server ID must be set in the MySQL config file, not as SQL commands.

4
Set up slave to replicate from master
On the slave server, set a unique server ID 2 in its configuration file. Then run the CHANGE MASTER TO command to connect to the master at host 'master_host' using user 'repl_user' and password 'repl_pass'. Finally, start the slave with START SLAVE;.
MySQL
Need a hint?

Set the slave's server ID in config. Use CHANGE MASTER TO with the master's host and replication user info. Then start the slave.