MySQL quickly adds slave nodes to the online master

Source: Internet
Author: User

Reprint: http://blog.longwin.com.tw/2008/07/mysql_set_master_slave_replication_fase_online_2008/

Already online MySQL Master, hope to be in the shortest possible time to do mysqldump, and then immediately let him restore on-line, so the main is to use--master-data, and then briefly read LOCK, mysqldump, UNLOCK action, Want to putTime reduced to the shortest possible ~

Note: If there is a full MySQL bin log, you can directly set up the replication, it will automatically start from the front of the binlog start scratching, even downtime is not necessary.

Operation Steps
SSH Master.hostname # First Set Master
Mysql> FLUSH TABLES with READ LOCK;
Cloning a Master.hostname# do Mysqldump
$ mysqldump-u root database_name--master-data > Database_name.sql
# If you do not add--master-data, you need to use show master status to write down the following syntax:
# change MASTER to master_host= ' master_hostname ', master_user= ' repl ', master_password= ' Repl_passord ', master_log_file = ' mysql-bin.000014 ', master_log_pos=232;
after dump, leave this terminal and go back to just MySQL
mysql> UNLOCK TABLES;
Mysql> quit
# to this master setting even if the completion, also has resumed the line, then comes down is slave ~


SSH Slave.hostname
$ SCP Master.hostname:DATABASE_NAME.sql
$ mysql-u Root
mysql> CREATE DATABASE database_name;
mysql> use database_name;
Mysql> source Database_name.sql;
# because the above has joined the--master-data command, so change master, etc., has been automatically added to the beginning of the file, but this change master does not write the master host information, so can be described in the following/etc/my.cnfSettings, or to modify the Database_name.sql, add change master to the host information. (The practice of modifying/ETC/MY.CNF is adopted here)
Mysql> quit
$ vim/etc/my.cnf

Log-bin=mysql-bin
Server-id = 3
Master-host = master_db. HOSTNAME
Master-user = Repl
Master-password = Repl_password
Master-port = 3306

$ sudo/usr/local/etc/rc.d/mysql-server Restart # BSD Preset path
$ mysql-u Root
mysql> start slave;
mysql> show Slave status \g

MySQL quickly adds slave nodes to the online master

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.