MySQL(Replication-MS)

mysql cluster mysql

高可用集羣(High Availability Cluster)
   雙master+keepalived
負載均衡集羣(Load Balance Cluster)
科學計算集羣(High Performance Computing Cluster)

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

[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.cnfide

[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 rootpost

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:code

  show master status
  show master logs
  show processlist
  reset masterorm

  show slave status
  show slave logs
  show processlist
  reset slaveserver

 

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 sqlip

replicate mode:
   statement level
   row level
   mixed levelssl

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  

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息