Logo

dev-resources.site

for different kinds of informations.

MySQL Master Slave Replication in Windows using XAMPP MySQL

Published at
12/21/2024
Categories
mysql
database
xampp
Author
chittrmahto
Categories
3 categories in total
mysql
open
database
open
xampp
open
Author
11 person written this
chittrmahto
open
MySQL Master Slave Replication in Windows using XAMPP MySQL

[email protected] Chirag's MySQL Tutorial https://www.chirags.in ************************************************************************

MySQL Master Slave Replication in Windows *************************************************************************

YouTube Video:
https://www.youtube.com/watch?v=kwBZldY-mdg

Database replication is the frequent electronic copying of data from a database in one computer or server to a database in another.

In this example, 02 XAMPP servers are being used.

Master – Server IP (Ex. 192.168.157.128) for demo I have localhost.
Slave – Server IP (Ex. 192.168.157.129)
    You need to install XAMPP with MySQL server on both master and slave machine or Install Two XAMPP in Same Machine. 
Enter fullscreen mode Exit fullscreen mode

PART 1 - In master server


Step 1. Login to Master Server.

Edit & Modify the Configuration file of MySQL.

log-bin Configuration in my.ini

log-bin="C:/mysql_master_logs/log-bin.log"
server-id = 1

bind-address = 127.0.0.1 #comment this line if you want to remotely access your server

Step 2. Restart MySQL Server. Step 3. Login to MySQL Server.

# mysql -u root -p
Step 4. Create a new user for Replication and specify the Password to that user.

MariaDB [(none)]> CREATE USER 'mysqlrepli'@'localhost' IDENTIFIED BY 'admin@123';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON . TO 'mysqlrepli'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
Example :

MariaDB [(none)]> CREATE USER 'replication_user'@'192.168.157.128' IDENTIFIED BY 'replica_password';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON . TO 'replication_user '@'192.168.157.128';
Step 5. binary logging # check binary logging

MariaDB [(none)]> show global variables like 'log_bin';

View the binary log location

MariaDB [(none)]> show global variables like '%log_bin%';

Show binary logs

MariaDB [(none)]> show binary logs;
Step 6. Execute below command to Lock Tables & take backup and view the File & Position of Master Server.

MariaDB [(none)]> FLUSH TABLES WITH READ LOCK;

C:\path >mysqldump -u root -p –all-databases –master-data > data.sql
Note: Path will be mysqldump.exe path.. It will be inside the bin folder.

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 764 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
PART - 2 - In Slave Server


Step 7. Login to Slave Server. Edit & Modify the Configuration file of MySql Server.

     # Find the following line:
    bind-address = 127.0.0.1
    # Replace it with the following line:
    bind-address = Slave-Server-IP
    #log-bin Configuration in my.ini
    log-bin="C:/mysql_slave_logs/log-bin.log"
    server-id = 2
Enter fullscreen mode Exit fullscreen mode

Restart MySQL Server Step

  1. Login to MySQL in Slave Server.

    # mysql -u root -p
    

    Step 9. Import Data Dump

    mysql -u root -p < data.sql
    

    Step 10. Specify the following details as given below & make sure to Replace the following settings with your settings.

    MASTER_HOST     :   IP Address of Master server
    MASTER_USER     :   Replication User of Master server that we had created in previous steps.
    MASTER_PASSWORD :   Replication User Password of Master server that we had created in previous steps.
    MASTER_LOG_FILE :   Your Value of Master Log File of Master server.
    MASTER_LOG_POS  :   Your Value of Master Log Position of Master server.
    
    MariaDB [(none)]> STOP SLAVE;
    MariaDB [(none)]>  CHANGE MASTER TO MASTER_HOST = 'localhost', MASTER_USER = 'mysqlrepli', MASTER_PASSWORD = 'admin@123', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 420;
    MariaDB [(none)]>  START SLAVE;
    MariaDB [(none)]>  show databases;
    MariaDB [(none)]>  SHOW SLAVE STATUS;
    ### Don’t forget to unlock the tables.
    

MariaDB [(none)]> UNLOCK TABLES;
PART - 3 - Testing for replication work


Step 10. Login to Master Server. Login to MySQL Server

    # mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Step 11. For testing a Replication we need to create a new database, it will automatically replicate on Slave Server.

    MariaDB [(none)]>   create database chiragdb;
Enter fullscreen mode Exit fullscreen mode

Step 12. Login to Slave Server. Login to MySQL Server

   # mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Step 13. View your Replicated Database by using below command.

    MariaDB [(none)]>   show databases;
Enter fullscreen mode Exit fullscreen mode

Let me know if you'd like further assistance!

For any doubts and query, please write on YouTube video comments section.

Note : Flow the Process shown in video.

😉Subscribe and like for more videos:

https://www.youtube.com/@chiragstutorial

💛Don't forget to, 💘Follow, 💝Like, 💖Share 💙&, Comment

Thanks & Regards,

Chitt Ranjan Mahto "Chirag"


Note: All scripts used in this demo will be available in our website.

Link will be available in description.

MySQLTutorial, #ChiragsMySQLTutorial, #CreateDatabaseinMySQL, #CreateTablesinMySQL, #MasterSlaveReplicationinMySQL, #MySQLReplication, #MySQLMasterSlave, #InstallMySQLinUbuntu, #InstallMySQLinLinux, #InstallMySQLinWindows

mysql Article's
30 articles in total
Favicon
MySQL ONLY_FULL_GROUP_BY Error: Easy Fixes and Best Practices
Favicon
Getting started on MOCO, the MySQL Operator for Kubernetes Part 1
Favicon
Configuring a Virtual IP (VIP) ensures seamless failover and high availability for MariaDB Galera Cluster on Ubuntu 24.04 LTS
Favicon
December 2024: How Releem Is Making MySQL Monitoring & Performance Tuning Easier
Favicon
A Top HR Service Company Replaces its System Seamlessly with BladePipe
Favicon
MySQLTuner for Windows: Common Issues and Better Alternatives
Favicon
Configure MariaDB Galera Cluster in ubuntu 24.04 LTS
Favicon
Laravel Eloquent ORM in Bangla Part-3 (Models Retrieving)
Favicon
How to Use SUBSTRING_INDEX in MySQL
Favicon
What is the current market demand for Laravel?
Favicon
Laravel Eloquent ORM in Bangla Part-1(Generating Model Classes)
Favicon
Choosing the Right Time Series Database for Your Use Case
Favicon
Subqueries
Favicon
Relational Database Design: DBMS
Favicon
How to Install MySQL on Ubuntu
Favicon
Try new challenge toh improve your self 😉👍
Favicon
Avoiding the Pitfalls of Duplicate Indexes in MySQL
Favicon
Continuación del Hilo: Cómo Crear una Aplicación de Finanzas Personales Integrando Google Drive, MySQL y Node.js
Favicon
Triggers in MySQL: Benefits and Drawbacks
Favicon
Can anyone help me with this? I'm working on xampp to setup my php using mysql. Even gtp is not able to solve this issue.
Favicon
HadiDB: A Lightweight, Horizontally Scalable Database in Python
Favicon
วิธีทำ Auth API ด้วย Express, JWT, MySQL และ Prisma
Favicon
When Should You Create Views in Your Database?
Favicon
MySQL Master Slave Replication in Windows using XAMPP MySQL
Favicon
How NL2SQL Tools Like Chat2DB Simplify Data
Favicon
TableSavvy ( MYSQL DATABASE MANAGEMENT SOFTWARE )
Favicon
Error
Favicon
Top 5 Text2SQL Tools for Effortless SQL Generation
Favicon
Introduction To MySQL & SQL QUERIES
Favicon
5 Reasons to Choose KLUSTERFIRST for Your MSSQL Database Needs

Featured ones: