• MySQL Replication Setup

    by  • June 25, 2012 • Linux, MySQL • 0 Comments

    The target uses for replication in MySQL include:

    • Scale-out solutions – spreading the load among multiple slaves to improve performance. In this environment, all writes and updates must take place on the master server. Reads, however, may take place on one or more slaves. This model can improve the performance of writes (since the master is dedicated to updates), while dramatically increasing read speed across an increasing number of slaves.
    • Data security – because data is replicated to the slave, and the slave can pause the replication process, it is possible to run backup services on the slave without corrupting the corresponding master data.
    • Analytics – live data can be created on the master, while the analysis of the information can take place on the slave without affecting the performance of the master.
    • Long-distance data distribution – if a branch office would like to work with a copy of your main data, you can use replication to create a local copy of the data for their use without requiring permanent access to the master.

    Install mysql-server package on master and slave.

    Now we have mysql server running on both servers.

    Prepare the master server.

    Edit /etc/my.cnf and add two lines in [mysqld] section
    log-bin=mysql-bin
    server-id=1

    Restart the mysqld service, create a user for replication  and lock the tables so that slave can be configured.

    Keep the mysql client alive until slave is configured.

    Note : If you are using iptables firewall on server, then use the command below to open connections to mysql.

    Open another client and check the log file name and position on master.

    Make a note of these and proceed to next steps….

    Prepare the slave server

    Edit /etc/my.cnf and add one line in [mysqld] section
    server-id=2

    Now restart service on slave and configure it to connect and replicate from master server.

    Now the slave is ready.

    Testing the setup

    Unlock the server and add some data.

    Now go to slave and check if the data has been replicated.

     

    Related posts:

    1. Basic PHP & MySQL Part 1

    About

    Leave a Reply

    Your email address will not be published. Required fields are marked *