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