mysql复制

row格式优势

1.比statement更加安全

2.在某些情况下复制速度更快(表带主键)

3.系统的特殊函数可以复制(uuid,sysdate)

4.更少的锁

row格式缺点

1.binary log 文件较大 (支持前镜像)

2.单语句更新表行数过多,会形成大量binlog

3.无法从binlog看见用户执行的sql (event:binlog_row_query_log_events,记录用户查询)

复制分类

1.异步复制

2.半同步复制

3.增强半同步

4.MGR

异步复制

mysql 5.7.19 + gitd + row

1.开启binlog

binlog_format =row 
log_bin =mysql-bin

2.开启GTID

gtid_mode =on 
enforce_gtid_consistency =on

3.配置server_id

server_id  = 1003306

4.查看gtid

show master status G;
*************************** 1. row ***************************
File: mysql-bin.000023
Position: 3577
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set: aa55f1f8-6f85-11e8-8f0e-c03fd53051da:1-126166

5.备份主库

 mysqldump --single-transaction   --master-data=2  -uroot -p -A -S /tmp/mysql.sock > /tmp/3306.sql

6.导入到从库

source /tmp/3306.sql

7.主库创建复制用户

create user 'repl'@'%' identified by 'repl'
grant replication slave on *.* to 'repl'@'%'

8.从库配置主库

change master to master_host='150.0.32.236',
master_user='repl',
master_password='repl',
master_port=3306 ,
master_auto_position=1;

9.启动slave

start slave;

10.查看复制情况

show slave status G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 150.0.32.236
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000023
Read_Master_Log_Pos: 4379
Relay_Log_File: gyweihu01-relay-bin.000002
Relay_Log_Pos: 4552
Relay_Master_Log_File: mysql-bin.000023
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 4379
Relay_Log_Space: 4763
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1003306
Master_UUID: aa55f1f8-6f85-11e8-8f0e-c03fd53051da
Master_Info_File: /home/mysql/mysqldata/3309/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: aa55f1f8-6f85-11e8-8f0e-c03fd53051da:126157-126170
Executed_Gtid_Set: aa55f1f8-6f85-11e8-8f0e-c03fd53051da:1-126170,
e1d1571f-75c1-11e8-92a6-c03fd53051da:1-2
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:

半同步复制(after commit)

会产生幻读,性能下降的厉害。

增强半同步(after sync)

不会产生幻读,性能没什么影响。增加了ack thread进程,减轻了dump thread压力。

原文地址:https://www.cnblogs.com/emmm233/p/9578845.html