0
MySQL REPLICATION Shishir Kumar Saha Software Engineer Tasawr Interactive [email_address]
What is replication? <ul><li>Copying data from one instance of MySQL to another where all results are guaranteed to be the...
Advantages <ul><li>Robustness </li></ul><ul><li>Load Balancing </li></ul><ul><li>Easy Backup </li></ul>
MySQL Replication Types <ul><li>Master-Slave Replication </li></ul><ul><li>Master-Master Circular Replication </li></ul>
Archetecture <ul><li>Master </li></ul><ul><li>- Connective Slaves </li></ul><ul><li>- Connective Masters </li></ul><ul><li...
Control Files <ul><li>Master </li></ul><ul><li>- hostname-bin.001  </li></ul><ul><li>- hostname-bin.index </li></ul><ul><l...
Master Setup <ul><li>Login to Master Database Server as root </li></ul><ul><li>Set up an account for replication </li></ul...
Master Setup Cont. <ul><li>For Master-Master Circular Replication: </li></ul><ul><li>grant all privileges on sff_productio...
Snapshot <ul><li>rsync/scp </li></ul><ul><li>copy a slave </li></ul><ul><li>mysqldump </li></ul>
Slave Setup <ul><li>Insert data/copy data into place </li></ul><ul><li>Configure my.cnf file  </li></ul><ul><li>For Simple...
SQL for Slave <ul><li>Stop Slave </li></ul><ul><li>Start Slave </li></ul><ul><li>Show Slave Status </li></ul>
What if it breaks? <ul><li>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n </li></ul><ul><li>Check MySql binlog </li></ul><ul><li>De...
Monitor Replication Status (Master) <ul><li>mysql> show processlist; </li></ul><ul><li>+----+---------+-------------------...
Monitor Replication Status (Master) <ul><li>mysql> show master status; </li></ul><ul><li>+----------------------+---------...
Monitor Replication Status (Slave) <ul><li>mysql> show processlist;  </li></ul><ul><li>+----+-------------+-----------+---...
Monitor Replication Status (Slave) <ul><li>mysql> show slave status; </li></ul><ul><li>+----------------------------------...
<ul><li>Question? </li></ul>
Upcoming SlideShare
Loading in...5
×

Basic Knowledge on MySql Replication

5,511

Published on

Mysql Replication Basics

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,511
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
152
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "Basic Knowledge on MySql Replication"

  1. 1. MySQL REPLICATION Shishir Kumar Saha Software Engineer Tasawr Interactive [email_address]
  2. 2. What is replication? <ul><li>Copying data from one instance of MySQL to another where all results are guaranteed to be the same on both end </li></ul><ul><li>Atomic </li></ul>
  3. 3. Advantages <ul><li>Robustness </li></ul><ul><li>Load Balancing </li></ul><ul><li>Easy Backup </li></ul>
  4. 4. MySQL Replication Types <ul><li>Master-Slave Replication </li></ul><ul><li>Master-Master Circular Replication </li></ul>
  5. 5. Archetecture <ul><li>Master </li></ul><ul><li>- Connective Slaves </li></ul><ul><li>- Connective Masters </li></ul><ul><li>Slaves </li></ul><ul><li>- I/O Threads </li></ul><ul><li>- SQL Threads </li></ul>
  6. 6. Control Files <ul><li>Master </li></ul><ul><li>- hostname-bin.001 </li></ul><ul><li>- hostname-bin.index </li></ul><ul><li>Slave </li></ul><ul><li>- master.info </li></ul><ul><li>- relay-log.info </li></ul><ul><li>- hostname-relay-bin.001 </li></ul><ul><li>- hostname-relay-bin.index </li></ul>
  7. 7. Master Setup <ul><li>Login to Master Database Server as root </li></ul><ul><li>Set up an account for replication </li></ul><ul><li>- mysql>GRANT REPLICATION SLAVE ON * TO &quot;slave&quot; IDENTIFIED BY &quot;slave_password&quot;; </li></ul><ul><li>Make a file named my.cnf (/etc/my.cnf) with contents – </li></ul><ul><li>For Simple Master-Slave Replication: </li></ul><ul><li>[mysqld] </li></ul><ul><li>log_bin </li></ul><ul><li>server-id=100 </li></ul>
  8. 8. Master Setup Cont. <ul><li>For Master-Master Circular Replication: </li></ul><ul><li>grant all privileges on sff_production.* to 'sff_159'@'74.50.56.157' identified by ‘sff_pass'; </li></ul><ul><li>grant all privileges on sff_production.* to 'sff_159'@'74.50.56.158' identified by ‘sff_pass'; </li></ul><ul><li>GRANT SUPER, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'sff_159'@'74.50.56.157, 74.50.56.158, 74.50.56.159'; </li></ul><ul><li>server-id = 30 </li></ul><ul><li>log-bin = /var/log/mysql/mysql-bin.log </li></ul><ul><li>log-slave-updates </li></ul><ul><li>replicate-same-server-id = 0 </li></ul><ul><li>auto_increment_increment = 10 </li></ul><ul><li>auto_increment_offset = 3 </li></ul><ul><li>master-host = 74.50.56.158 </li></ul><ul><li>master-user = sff_158 </li></ul><ul><li>master-password = sff_pass </li></ul><ul><li>report-host = 74.50.56.159 </li></ul><ul><li>replicate-do-db = sff_production </li></ul><ul><li>sync_binlog = 1 </li></ul><ul><li>slave_exec_mode = IDEMPOTENT </li></ul><ul><li>Restart MySql Server </li></ul>
  9. 9. Snapshot <ul><li>rsync/scp </li></ul><ul><li>copy a slave </li></ul><ul><li>mysqldump </li></ul>
  10. 10. Slave Setup <ul><li>Insert data/copy data into place </li></ul><ul><li>Configure my.cnf file </li></ul><ul><li>For Simple Master-Slave Replication: </li></ul><ul><li>[mysqld] </li></ul><ul><li>log_bin </li></ul><ul><li>server-id=101 </li></ul><ul><li>For Master-Master Circular Replication: </li></ul><ul><li>Same as master server </li></ul><ul><li>Set master position, </li></ul><ul><li>change master to MASTER_HOST=‘master ip', MASTER_USER='client', MASTER_PASSWORD='abc', master_log_file=’ localhost-bin.001’,master_log_pos=79; </li></ul><ul><li>Start replication </li></ul>
  11. 11. SQL for Slave <ul><li>Stop Slave </li></ul><ul><li>Start Slave </li></ul><ul><li>Show Slave Status </li></ul>
  12. 12. What if it breaks? <ul><li>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n </li></ul><ul><li>Check MySql binlog </li></ul><ul><li>Delete the relay logs </li></ul><ul><li>Restart Replication </li></ul>
  13. 13. Monitor Replication Status (Master) <ul><li>mysql> show processlist; </li></ul><ul><li>+----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+------------------+ </li></ul><ul><li>| Id | User | Host | db | Command | Time | State | Info | </li></ul><ul><li>+----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+------------------+ </li></ul><ul><li>| 1 | root | localhost | NULL | Query | 0 | NULL | show processlist | </li></ul><ul><li>| 2 | client1 | 202.161.134.117:32777 | NULL | Binlog Dump | 419 | Has sent all binlog to slave; waiting for binlog to be updated | NULL | </li></ul><ul><li>+----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+--------- </li></ul>
  14. 14. Monitor Replication Status (Master) <ul><li>mysql> show master status; </li></ul><ul><li>+----------------------+-----------+--------------+------------------+ </li></ul><ul><li>| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | </li></ul><ul><li>+----------------------+-----------+--------------+------------------+ </li></ul><ul><li>| localhost-bin.000001 | 957574845 | | | </li></ul><ul><li>+----------------------+-----------+--------------+------------------+ </li></ul>
  15. 15. Monitor Replication Status (Slave) <ul><li>mysql> show processlist; </li></ul><ul><li>+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+ </li></ul><ul><li>| Id | User | Host | db | Command | Time | State | Info | </li></ul><ul><li>+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+ </li></ul><ul><li>| 2 | system user | | NULL | Connect | 406 | Waiting for master to send event | NULL | </li></ul><ul><li>| 3 | system user | | NULL | Connect | 861 | Has read all relay log; waiting for the slave I/O thread to update it | NULL | </li></ul><ul><li>| 4 | root | localhost | NULL | Query | 0 | NULL | show processlist | </li></ul><ul><li>+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+-------------- </li></ul>
  16. 16. Monitor Replication Status (Slave) <ul><li>mysql> show slave status; </li></ul><ul><li>+----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ </li></ul><ul><li>| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | </li></ul><ul><li>+----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ </li></ul><ul><li>| Waiting for master to send event | 74.50.56.157 | gent333 | 3306 | 60 | localhost-bin.000001 | 958545954 | localhost-relay-bin.000004 | 56204926 | localhost-bin.000001 | Yes | Yes | | | | | | | 0 | | 0 | 958545954 | 56204926 | None | | 0 | No | | | | | | 0 | </li></ul><ul><li>+----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+ </li></ul>
  17. 17. <ul><li>Question? </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×