How to Setup MySQL (Master-Slave) Replication in RHEL, CentOS, Fedora

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

162 Responses

  1. Muhammad Ahtsham says:

    Good Job Buddy! It really helped me.

  2. anshul says:

    Sir what if i have to replicate more than one database from same same master server to slave.

    • Ravi Saive says:


      You can create x number MySQL clusters, just make sure you’ve mentioned correct MySQL id in /etc/my.conf file for each node..

  3. Gulshan Upadhyay says:

    Failed to import dbdump file on slave side….

    Getting error while running the command….

    # mysql -u root -p < /root/dbdump.db (On the slave node)

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    I have same os on both machine (i.e. Rhel7)

    Plz.. give complete solution

    • Ravi Saive says:


      Please make sure that MySQL started and running, if not you can start it using:

      # service mysqld restart
      # systemctl restart mysqld
  4. Rusdi says:

    Thankyou so much pals for this superb great tutorial. It really helpful.

  5. Tapas Sen says:


    Getting error while running the command….

    # mysql -u root -p < dbstore.db (On the slave node)

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

  6. Muhammad Shidiq says:

    I’ve two VM located on Digital Ocean and Microsoft Azure, I use my Digital Ocean as master and Microsoft Azure as slave. Can I implement replication in different server like Digital Ocean and Azure?

    • Ravi Saive says:


      Not possible, both servers must be same Linux OS to do database Master/Slave replication…

      • Muhammad Shidiq says:

        Hi Ravi,

        I mean same OS (linux) but different server. I’ve ubuntu in DO and Azure, so can I do master-slave replication?

        • Ravi Saive says:


          As fas as both machine with different Linux OS will work without any issues, yes you can do a master-slave MySQL replication without any doubt…:)

  7. yogesh says:

    thanks for reply..can u please make tutorial on or write blog for how to use replication for wamp server one slave and multiple masters.Thanks.

  8. Yogesh says:

    nice post..I am using master on windows,and my server is on cent-OS..whenever I try to run CHANGE MASTER TO…. this gives me error like slave is not configured or server_id is not set on master or slave…Thanks

    • Yogesh says:

      I am doing this with WAMP3 Server.

      • Ravi Saive says:


        If am not wrong WAMP means Windows, Apache, MySQL and PHP? if yes, then how come these commands work on Windows? better have a Linux..

    • Ravi Saive says:


      I don’t think it will work that way, both machines must be Linux OS.

      • Yogesh says:

        Slave is not configured or failed to initialize properly. You must at least set –server-id to enable either a master or a slave.
        now I am getting this error..1st time its work after second time when I try to look out through START SLAVE…STOP SLAVE its produced this error..can u explain why?

        | Variable_name | Value |
        | server_id | 11 |

        my.cnf file has
        server_id = 11
        replicate_do_db = dbname

        • yogesh says:

          pls reply I stuck on this error…

          • Ravi Saive says:


            Sorry, as I said it’s difficult to answer you question, as you’re using two different OS’s for same purpose, and I don’t think it work that way, both machine must be Linux operating systems, in order to work properly…..

  9. Ahmet Mert ALPAT says:

    Great Article. Works Fine.. Thanks so much. Appreciate !

  10. Amit says:

    Awesome!!!! Really thanks for the post,, and its working perfectly

Leave a Reply to Rusdi Cancel reply

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.