MySQL(Replication)
博客专区 > 赵-猛 的博客 > 博客详情
MySQL(Replication)
赵-猛 发表于1年前
MySQL(Replication)
  • 发表于 1年前
  • 阅读 11
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

master: .\bin\mysqld --defaults-file=.\my.ini 
create directory: D:/Server/mysql/mysql-master/tmp and D:/Server/mysql/mysql-master/data 

[mysqld] 
server-id=1 
#replicate-same-server-id=0 
basedir = D:/Server/mysql/mysql-master  
datadir = D:/Server/mysql/mysql-master/data 
tmpdir = D:/Server/mysql/mysql-master/tmp 
port = 3310 
log-bin=master-bin 
log-bin-index=master-bin.index 
join_buffer_size = 128M 
sort_buffer_size = 2M 
read_rnd_buffer_size = 2M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
[client] 
port = 3310 


master-client: .\bin\mysql -h localhost -P 3310  -u root

grant replication slave, replication client on *.* to repl@'localhost' identified by 'password';

 

slave: .\bin\mysqld --defaults-file=.\my.ini 
create directory: D:/Server/mysql/mysql-slave/tmp and D:/Server/mysql/mysql-slave/data
change the UUID(should be different with the master) in auto.cnf

[mysqld] 
server-id=2 
#replicate-same-server-id=0 
innodb_buffer_pool_size = 128M 
basedir = D:/Server/mysql/mysql-slave 
datadir = D:/Server/mysql/mysql-slave/data 
tmpdir = D:/Server/mysql/mysql-slave/tmp 
port = 3311 
log_bin           = slave-bin
relay-log = slave-relay-bin 
relay-log-index = slave-relay-bin.index 
log_slave_updates = 1
skip-name-resolve
slave-skip-errors = all
read_only         = 1
join_buffer_size = 128M 
sort_buffer_size = 2M 
read_rnd_buffer_size = 2M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
##master-host     =   localhost
##master-user     =   repl
##master-password =   password
##master-port     =  3310
[client] 
port = 3311 


slave-client: .\bin\mysql -h localhost -P 3311 -u root

stop slave
change master to master_host='localhost',master_port=3310,master_user='repl',master_password='password', master_log_file='master-bin.000001',master_log_pos=0; 
start slave

 

some script:

  show master status
  show master logs
  show processlist
  reset master

  show slave status
  show slave logs
  show processlist
  reset slave

 

replicate flow:
   slave io process connect to master
   master io process write bin-log to slave
   slave io process write sql to relay-log
   slave sql process parse relay-log and execute sql

replicate mode:
   statement level
   row level
   mixed level

replicate slave fail mode:
    slave_exec_mode = strict: default
    slave_exec_mode = idempotent: 忽略duplicate-key, no-key-found和一些其他错误

replicate threads:
    master host: IO process
    slave host:IO process + SQL process


replicate config file:
    server-id = 2
    replicate-wild-ignore-table=mysql.%
    log-slave-updates
    replicate-ignore-db = mysql
    replicate-ignore-db = test
    binlog-ignore-db = mysql
    binlog-ignore-db = test
    replicate-do-db = xx
    binlog-do-db = xx
    replicate-do-db = xx
    binlog-do-db = xx
    replicate-do-db = xx
    binlog-do-db = xx
    replicate-do-db = xx
    binlog-do-db = xx
    replicate-do-db = xx
    binlog-do-db = xx


binlog skip error:
  使用SET GLOBAL SQL_SLAVE_SKIP_COUNTER 命令跳过失败的SQL
    slave stop
    set global sql_slave_skip_counter=1
    slave start
  (or slave_skip_errors = 1062 in my.cnf)

binlog variables:
  show variables like '%bin%';

binlog files:
  ll /data/mysql/binlog*
  or sudo cat /data/mysql/binlog.index

show binlog:
  show binary logs;
  show master logs

show status:
  show master status\G;
  show stalve status\G;

show binlog event:
  show binlog events;
  binlog events in 'binlog.000178';
  binlog events in 'binlog.000178' from 92562567 limit 100;

show binlog sql:
  sudo mysqlbinlog  /data/mysql/binlog.000178|grep -C 5 'qpfp.com.cn2017-01-07 04:27:42'
  sudo mysqlbinlog  --start-datetime='2013-09-10 00:00:00' --stop-datetime='2013-09-10 01:01:01' --database=zm /data/mysql/binlog.000178 |grep -A 5 'qpfp.com.cn2017-01-07 04:27:42'
  sudo mysqlbinlog  --start-postion=107 --stop-position=1000 --database=zm /data/mysql/binlog.000178 |grep -B 5 'qpfp.com.cn2017-01-07 04:27:42'

limit logs days:
  set global expire_logs_days=3


relaylog:
  set relay_log_recovery=1

slave reset recovery:
  slave stop
  change master to master_log_file='yyyy-relay-bin.nnnn', master_log_pos=m
  slave start
 

标签: MySQL Replication
共有 人打赏支持
粉丝 5
博文 78
码字总数 390081
×
赵-猛
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: