1、准备多实例

  (1)主库授权创建用户

    grant replication slave on *.* to repl@'10.0.0.*' identified by 'ruan';    

2、从库恢复主库历史数据

  (1)备份主库数据

    mysqldump -uroot -p -S /tmp/mysql.sock -master-data=2 --single-tranaction --triggers >/tmp/full.sql

  (2)从库恢复主库历史数据

    help change master to    找配置信息

    

CHANGE MASTER TO
  MASTER_HOST='10.0.0.200',     
  MASTER_USER='repl',
  MASTER_PASSWORD='ruan',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='mysql-bin.000002',
  MASTER_LOG_POS=1182,
  MASTER_CONNECT_RETRY=10;

 

  (3)开启线程(IO,SQL)

start slave;

   (4)清空从库配置信息

reset slave all;

  (5)关闭线程(IO,SQL)

stop slave;

  (6)单独关闭线程

stop slave io_thread;
stop slave sql_thread;

 

 

 

 将从库设为只读库

  set global read_only=1 或者编辑my.cnf

  innodb_read_only=1  对root用户也生效

 

3、从库延时

  change master to master_delay=300;