Cool Dba

  • Home
  • Sql tricks
  • Security
  • Maintainance
  • Backups
  • Recovery
  • Replication
  • Installation
  • Linux

Sunday, May 22, 2016

Master-Slave Replication without downtime

 Anil Joshi     10:27 PM     Replication     No comments   



First, we configure master’s /etc/mysql/my.cnf by including these lines in the [mysqld] section:


server-id=1
binlog-format = mixed
log-bin=mysql-bin
datadir=/var/lib/mysql
innodb_flush_log_at_trx_commit=1
sync_binlog=1
Restart the master mysql server and create a user with replication permission that your slave server will use to connect to the master:
CREATE USER repl@slave-server-ip;
GRANT REPLICATION SLAVE ON *.* TO rep@slave-server-ip IDENTIFIED BY 'password';
Next, create the dump file with the binlog position. It will affect the performance of  database, but won’t lock your tables:
mysqldump --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 -A  > /dump.sql
Now, examine the head of the file and write down the values for MASTER_LOG_FILE and MASTER_LOG_POS. You will need them later:
head dump.sql -n80 | grep "MASTER_LOG_POS"
compress the file with gzip
gzip dump.sql
Next, you need to transfer the dump file to our slave server 
scp dump.sql.gz username@slave-server-ip:/directory/
Next, you should log into your slave server, and edit /etc/mysql/my.cnf file to add the following lines:
server-id     = 2
binlog-format = mixed
log_bin       = mysql-bin
relay-log     = mysql-relay-bin
log-slave-updates = 1
read-only         = 1
Restart the mysql slave, and then import your dump file:
gunzip dump.sql.gz
mysql -u root -p < /dump.sql
Log into your mysql prompt on your slave server and run the following commands to start replication:
CHANGE MASTER TO MASTER_HOST ='master_ip',MASTER_USER='repl',
MASTER_PASSWORD='password', MASTER_LOG_FILE='value from above', MASTER_LOG_POS=value from above>;
START SLAVE;
To check the progress of your slave:
SHOW SLAVE STATUS \G
If all is well, Last_Error will be blank, and Slave_IO_State will report “Waiting for master to send event”. Look for Seconds_Behind_Master which indicates how far behind it is. It took me a few hours to accomplish all of the above.
Sometimes errors occur in replication. For example, if you accidentally change a row of data on your slave. If this happens, fix the data, then run:
 STOP SLAVE;SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;START SLAVE;



  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Deals on Amazon

Mobiles on Amazon

About Me

My photo
Anil Joshi
New Delhi, Delhi, India
I am a simple man with little knowledge of computer software and Tehnology.
View my complete profile

Popular Posts

  • SELinux mechanism in linux environment.
    Security-Enhanced Linux (SELinux) is a mandatory access control (MAC) security mechanism implemented in the kernel. SELinux was first ...
  • Simple bash script's for managing mysql
    1. Monitoring replication health #!/bin/bash sql_thread_running=$(mysql -e "show slave status\G" | awk -F":" ...
  • Finding and preventing ddos attack on Linux Server
    A distributed denial-of-service (DDoS) attack occurs when multiple systems flood the bandwidth or resources of a targeted system, usual...
  • Master-Slave Replication without downtime
    First, we configure master’s   /etc/mysql/my.cnf   by including these lines in the [mysqld] section: server - id = 1 bin...
  • Mysql Security
    Improved  MySQL Database Se curity 1. Secure your server Many known attacks are possible only once physical access to a machi...
  • Check and Repair Mysql Tables
      Check a Specific Table in a Database If your application throws an error message saying that a specific table is corrupted, exe...
  • Filter Replication Variables
    Filtering can be done on the Master or on the Slave. Filtering on the Slave is normally preferred as in this case you get full binary lo...
  • Complete uninstallation of Mysql Server on centos
    Step 1: Check list the mysql rpm which is installed on server rpm -qa | grep mysql or yum list installed | grep mysql Step 2 : Re...
  • Recovering InnoDB MySQL Tables Data from ibdata and .frm Files
    First Check Error Logs. InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes InnoDB: than specified in th...
  • Tracing the execution of processes using strace
    Strace is quite simply a tool that traces the execution of system calls. It can trace the execution of a binary from start to end, and ou...
Best Shoes on amazon

Categories

  • Backups
  • Database Maintainance
  • Installation
  • Linux
  • Mysql
  • Recovery
  • Replication
  • Scripts
  • Security
  • SELinux
  • sql tricks
  • Strace

Pages

  • Home

Blog Archive

  • ▼  2016 (19)
    • ►  June (1)
    • ▼  May (18)
      • Finding and preventing ddos attack on Linux Server
      • Tracing the execution of processes using strace
      • SELinux mechanism in linux environment.
      • Simple bash script's for managing mysql
      • Running multiple mysql instance on single server(C...
      • Mysql Installation using rpm package
      • Check and Repair Mysql Tables
      • Dual Master Replication(Master-Master)
      • Filter Replication Variables
      • Master-Slave Replication without downtime
      • How to Export and Import files in Mysql
      • Recovering InnoDB MySQL Tables Data from ibdata ...
      • Check Database Size,Compare tables & column Differ...
      • Store Procedure & Views Backups
      • Mysql Security
      • MySQL Restart Failed
      • Running select statement inside an update query
      • Mass Killing Mysql Process

Sample Text

Copyright © Cool Dba | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates