MySQL :How to Configure Mysql master slave replication in MYSQL database

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • MySQL :How to Configure MySQL Master-Slave Replication on RHEL
    *********************************************************************
    MySQL replication procedure enabled you to automatically copy data from one MYSQL database server to one or more MYSQL servers.
    MySQL supports a number of replication topologies with Master/Slave topology being one of the most well-known topologies in which
    one database server acts as the master, while one or more servers act as slaves. By default, the replication is asynchronous where
    the master sends events that describe database modifications to its binary log and slaves request the events when they are ready.
    This sort of replication topology is good for deploying of read replicas for read scaling, live databases backup
    for disaster recovery and for analytics jobs.
    MySQL 8.0 supports different methods of replication. The traditional method is based on replicating events from the master's binary log,
    and requires the log files and positions in them to be synchronized between master and slave.
    Prerequisites
    *************
    Setup
    *******
    ROLE HOST OS MYSQL SERVER VERSION
    Master 192.168.1.51(linux2) OEL 6.5 8.0.19
    Slave 192.168.1.61(linux3) OEL 6.5 8.0.19
    vaidate value of
    show variables like '%uuid%';
    Step 1: Configure the Master Server.
    *************************************
    -Let's configure the master MySQL server and perform below changes.
    -enable MySQL server to listen on the private IP.
    -Set a unique server ID.
    -Enable the binary logging.
    #
    cp /etc/my.cnf /etc/my.cnf_bkp_5may2020
    vi /etc/my.cnf
    bind-address = 192.168.1.51
    server-id = 1
    log_bin = mysql-bin
    -Once done, restart the MySQL service for changes to take effect
    service mysqld restart
    -create a new replication user who can login master server from slave server.
    [root@linux2 ~]#
    mysql -u root -p
    Mysql@1234
    SHOW MASTER STATUS\G
    ************************** 1. row **************************
    File: mysql-bin.000022
    Position: 155
    Binlog_Do_DB:
    Binlog_Ignore_DB:
    Executed_Gtid_Set:
    1 row in set (0.01 sec)
    CREATE USER 'replica'@'192.168.1.61' IDENTIFIED WITH mysql_native_password BY 'Password@123';
    GRANT REPLICATION SLAVE ON . TO 'replica'@'192.168.1.61';
    Select host, user from mysql.user;
    [root@linux3 ~]# mysql -u replica -h 192.168.1.51 -p
    Step 2 : [root@linux3 ~]#CONFIGURE THE SLAVE SERVER
    ***************************************************
    Like master server perform below changes on slave server.
    Set the MySQL server to listen on the private IP
    Set a unique server ID
    Enable the binary logging
    slave:/etc/my.cnf
    cp /etc/my.cnf /etc/my.cnf_orig
    vi /etc/my.cnf
    bind-address = 192.168.1.61
    server-id = 2
    log_bin = mysql-bin
    service mysqld restart
    Step 3: Configure the parameters for slave server to connect to the master server.
    ***********************************************************************************
    mysql -uroot -p
    Mysql@1234
    STOP SLAVE;
    CHANGE MASTER TO
    MASTER_HOST='192.168.1.51',
    MASTER_USER='replica',
    MASTER_PASSWORD='Password@123',
    MASTER_LOG_FILE='mysql-bin.000023',
    MASTER_LOG_POS=686;
    start slave;
    show slave status\G;
    show variables like '%uuid%';
    testing
    *******
    Create database testreplica;
    use testreplica;
    CREATE TABLE `departments` (
    `dept_no` char(4) NOT NULL,
    `dept_name` varchar(40) NOT NULL,
    PRIMARY KEY (`dept_no`),
    UNIQUE KEY `dept_name` (`dept_name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

ความคิดเห็น • 55

  • @akky948
    @akky948 11 หลายเดือนก่อน +1

    how to do maintenance of master-slave replication, like for Master DB we need to reboot but no downtime so , in this case can we do one thing like slave server become master and vice versa so we can reboot the server and then again change it back to previous

    • @bobbogenie
      @bobbogenie หลายเดือนก่อน

      Been wondering that as well

  • @oah8465
    @oah8465 ปีที่แล้ว

    fantastic video, but what format is the bin-log using? is it row based replication or SBR or is it mixed?
    and also this works only for brand new databases, right? because if we have old data on the master, i guess it is not being copied to the server.

  • @aldrinjohnencina6153
    @aldrinjohnencina6153 6 หลายเดือนก่อน

    you explained well. thank you so much

  • @dahuzihaidao
    @dahuzihaidao ปีที่แล้ว

    Nice video! Just one question, if I have Mysql-Master deployed on Server A using Docker, what should change to implement a Slave MySQL on Server B? Many thanks! :)

  • @jessicawang5363
    @jessicawang5363 2 ปีที่แล้ว

    Clarified my confusions, thank you

  • @massoudrahimzadeh1689
    @massoudrahimzadeh1689 ปีที่แล้ว

    Hi there, thank you for the nice tutorial. I have a question, who (which role) in an organised company is responsible for configuring a replication or server side tasks in general?
    What skills are needed?

  • @gati9907
    @gati9907 3 ปีที่แล้ว +1

    Perfect video . Thanks for sharing

  • @Private-GtngxNMBKvYzXyPq
    @Private-GtngxNMBKvYzXyPq 2 ปีที่แล้ว

    Good demonstration and tutorial. Thank you.

  • @sovrinfo
    @sovrinfo ปีที่แล้ว

    Great video. Big Thanks!

  • @muhammadazeem3444
    @muhammadazeem3444 3 ปีที่แล้ว +1

    Thanks, but I have a question. did we can reverse this action synchronization as slave to master. Let me explain. I am using a database under a website and its replication at different server. Now I point my domain to other server that holding slave database will it work fine as like master database. If yes, Now changes will in the slave database and its replication can be handle in the master. two way replication at the same time.

  • @AB-mi3mm
    @AB-mi3mm 2 ปีที่แล้ว +1

    Thank you for excellent videos and for .txt

  • @mohammadhussain8896
    @mohammadhussain8896 ปีที่แล้ว

    hey how do you make the master and slave instances and have different IP addresses, linux3, linux2?

  • @alemamangeldinov3880
    @alemamangeldinov3880 3 ปีที่แล้ว

    great video, thanks. make more

  • @veladisravankumar2635
    @veladisravankumar2635 3 ปีที่แล้ว

    Thank You, It's working fine to me. My doubt is, we pointed one binlog file name to slave db. But after few days running mysql, new binlog files will generate ? then how it will work. Out pointed binlog will be old one. Please give your suggestions..

  • @akshayarya1811
    @akshayarya1811 6 หลายเดือนก่อน

    on the slave status, i'm getting Last_IO_error : "The slave IO thread stops because master and slave have equal mysql server ids", However i've used different server ids in both the my.cnf files. Can you please help

  • @SilvermanWKWK
    @SilvermanWKWK 2 ปีที่แล้ว

    I have problem with connection slave dont wanna connect to master. can you help me?
    I have error code MY-0002003

  • @ilyesmazouzi3632
    @ilyesmazouzi3632 3 ปีที่แล้ว

    thanks for sharing

  • @carloscoliver9427
    @carloscoliver9427 3 ปีที่แล้ว

    Hi My friend... Excellent vídeo! But I have a task to make the DB replica in the same physical server, to be used for testing purposes, and not deal with production DB. Would it be possible with this method? What would be the changes I have to make?

    • @EMultiSkillsDatabaseServices
      @EMultiSkillsDatabaseServices  3 ปีที่แล้ว

      Yes it's possible . I will try to make a video on that once the time allows

    • @carloscoliver9427
      @carloscoliver9427 3 ปีที่แล้ว

      @@EMultiSkillsDatabaseServices thank You very very much for the fast reply, My dear friend. In the meantime, Could You enlight me with any link for that subject, for me to read or follow,? Because I think the assignment has to be done in few days. Sorry, again for me to bother you

    • @EMultiSkillsDatabaseServices
      @EMultiSkillsDatabaseServices  3 ปีที่แล้ว

      Did you try creating it ? Did you face an issue

    • @mandadapusateesh9612
      @mandadapusateesh9612 3 ปีที่แล้ว

      @@EMultiSkillsDatabaseServices I need the same can u provide any doc r video related to that..

    • @massoudrahimzadeh1689
      @massoudrahimzadeh1689 ปีที่แล้ว

      Hi, What is your role? I am asking because trying to figure it out who is responsible for the server side tasks and what skills is needed

  • @matthewbrown4572
    @matthewbrown4572 3 ปีที่แล้ว

    Does this method work with multiple machines? I want to write to a database on one computer and have that same update show up on another computer

  • @ahosanhabib9399
    @ahosanhabib9399 3 ปีที่แล้ว

    thanks a lot

  • @JahulHasan
    @JahulHasan 2 ปีที่แล้ว

    Hi
    Can we do Master-Slave Configuration on the same server?

  • @sarmadmalik6920
    @sarmadmalik6920 3 ปีที่แล้ว

    Hi
    Can u please tell master slave is applicable on two different version of mysql
    Master mysql verion 5.7.31
    Slave mysql version 8.0.22

    • @EMultiSkillsDatabaseServices
      @EMultiSkillsDatabaseServices  3 ปีที่แล้ว

      Officially MySQL supports replication from one release series to the next higher release series.
      You can replicate from a source running MySQL 5.7.* to a replica running MySQL 8.0.*
      You might see some issues due to some functionality working in lower version and obsolete in higher version.

  • @aakashroy7753
    @aakashroy7753 3 ปีที่แล้ว

    Please tell the steps to create master slave replication where slaves will be 2.
    Please put the steps. its a request

    • @EMultiSkillsDatabaseServices
      @EMultiSkillsDatabaseServices  3 ปีที่แล้ว

      Are these 2 slaves on 2 different hosts?

    • @aakashroy7753
      @aakashroy7753 3 ปีที่แล้ว

      @@EMultiSkillsDatabaseServices correct. 2 slaves on different servers. And master is on different server. The scenario is 1 master 2 slaves

  • @nickzouein
    @nickzouein ปีที่แล้ว

    Can you do us this tutorial with Phpmyadmin please? we are using windows as host.

  • @muhammadazeem3444
    @muhammadazeem3444 3 ปีที่แล้ว

    Can we make database replication on the share hosting?

    • @EMultiSkillsDatabaseServices
      @EMultiSkillsDatabaseServices  3 ปีที่แล้ว

      yes, that's possible and good for testing purpose as well.

    • @muhammadazeem3444
      @muhammadazeem3444 3 ปีที่แล้ว

      @@EMultiSkillsDatabaseServices But Want to develop a desktop application that can make database replication real time as well as data like files, directory images, docs etc that may be a specific directory or a complete project.

    • @muhammadazeem3444
      @muhammadazeem3444 3 ปีที่แล้ว

      will you to work on it. I already searching experienced person who can assist or can develop it.

    • @muhammadazeem3444
      @muhammadazeem3444 3 ปีที่แล้ว

      I post project on fiverr and upwork still not found a special one that can do this. still interviewing from last two days.

  • @tamoorali2863
    @tamoorali2863 3 ปีที่แล้ว

    can i get notes of replication

  • @mauromezzina8966
    @mauromezzina8966 ปีที่แล้ว

    Amazing tutorial, thank you very much!