• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Basic Knowledge on MySql Replication
 

Basic Knowledge on MySql Replication

on

  • 5,367 views

Mysql Replication Basics

Mysql Replication Basics

Statistics

Views

Total Views
5,367
Views on SlideShare
5,360
Embed Views
7

Actions

Likes
6
Downloads
111
Comments
0

2 Embeds 7

http://www.slideshare.net 6
http://localhost 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Basic Knowledge on MySql Replication Basic Knowledge on MySql Replication Presentation Transcript

    • MySQL REPLICATION Shishir Kumar Saha Software Engineer Tasawr Interactive [email_address]
    • What is replication?
      • Copying data from one instance of MySQL to another where all results are guaranteed to be the same on both end
      • Atomic
    • Advantages
      • Robustness
      • Load Balancing
      • Easy Backup
    • MySQL Replication Types
      • Master-Slave Replication
      • Master-Master Circular Replication
    • Archetecture
      • Master
      • - Connective Slaves
      • - Connective Masters
      • Slaves
      • - I/O Threads
      • - SQL Threads
    • Control Files
      • Master
      • - hostname-bin.001
      • - hostname-bin.index
      • Slave
      • - master.info
      • - relay-log.info
      • - hostname-relay-bin.001
      • - hostname-relay-bin.index
    • Master Setup
      • Login to Master Database Server as root
      • Set up an account for replication
      • - mysql>GRANT REPLICATION SLAVE ON * TO "slave" IDENTIFIED BY "slave_password";
      • Make a file named my.cnf (/etc/my.cnf) with contents –
      • For Simple Master-Slave Replication:
      • [mysqld]
      • log_bin
      • server-id=100
    • Master Setup Cont.
      • For Master-Master Circular Replication:
      • grant all privileges on sff_production.* to 'sff_159'@'74.50.56.157' identified by ‘sff_pass';
      • grant all privileges on sff_production.* to 'sff_159'@'74.50.56.158' identified by ‘sff_pass';
      • GRANT SUPER, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'sff_159'@'74.50.56.157, 74.50.56.158, 74.50.56.159';
      • server-id = 30
      • log-bin = /var/log/mysql/mysql-bin.log
      • log-slave-updates
      • replicate-same-server-id = 0
      • auto_increment_increment = 10
      • auto_increment_offset = 3
      • master-host = 74.50.56.158
      • master-user = sff_158
      • master-password = sff_pass
      • report-host = 74.50.56.159
      • replicate-do-db = sff_production
      • sync_binlog = 1
      • slave_exec_mode = IDEMPOTENT
      • Restart MySql Server
    • Snapshot
      • rsync/scp
      • copy a slave
      • mysqldump
    • Slave Setup
      • Insert data/copy data into place
      • Configure my.cnf file
      • For Simple Master-Slave Replication:
      • [mysqld]
      • log_bin
      • server-id=101
      • For Master-Master Circular Replication:
      • Same as master server
      • Set master position,
      • change master to MASTER_HOST=‘master ip', MASTER_USER='client', MASTER_PASSWORD='abc', master_log_file=’ localhost-bin.001’,master_log_pos=79;
      • Start replication
    • SQL for Slave
      • Stop Slave
      • Start Slave
      • Show Slave Status
    • What if it breaks?
      • SET GLOBAL SQL_SLAVE_SKIP_COUNTER = n
      • Check MySql binlog
      • Delete the relay logs
      • Restart Replication
    • Monitor Replication Status (Master)
      • mysql> show processlist;
      • +----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+------------------+
      • | Id | User | Host | db | Command | Time | State | Info |
      • +----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+------------------+
      • | 1 | root | localhost | NULL | Query | 0 | NULL | show processlist |
      • | 2 | client1 | 202.161.134.117:32777 | NULL | Binlog Dump | 419 | Has sent all binlog to slave; waiting for binlog to be updated | NULL |
      • +----+---------+-----------------------+------+-------------+------+----------------------------------------------------------------+---------
    • Monitor Replication Status (Master)
      • mysql> show master status;
      • +----------------------+-----------+--------------+------------------+
      • | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
      • +----------------------+-----------+--------------+------------------+
      • | localhost-bin.000001 | 957574845 | | |
      • +----------------------+-----------+--------------+------------------+
    • Monitor Replication Status (Slave)
      • mysql> show processlist;
      • +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+
      • | Id | User | Host | db | Command | Time | State | Info |
      • +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+------------------+
      • | 2 | system user | | NULL | Connect | 406 | Waiting for master to send event | NULL |
      • | 3 | system user | | NULL | Connect | 861 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
      • | 4 | root | localhost | NULL | Query | 0 | NULL | show processlist |
      • +----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------+--------------
    • Monitor Replication Status (Slave)
      • mysql> show slave status;
      • +----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
      • | 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 |
      • +----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
      • | 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 |
      • +----------------------------------+---------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
      • Question?