mysql algorithm copy_mysql 复制检查工具mk-table-checksum replicate选项

type: string

Replicate checksums to slaves (disallows --algorithm CHECKSUM).

This option enables a completely different checksum strategy for a consistent,

lock-free checksum across a master and its slaves

. Instead of running

the

checksum queries on each server, you run them only on the master. You

specify a

table, fully qualified in db.table format, to insert the results into.

The

checksum queries will insert directly into the table, so they will be

replicated

through the binlog to the slaves.

When the queries are finished replicating, you can run a simple query

on each

slave to see which tables have differences from the master. With the

--replicate-check

option, mk-table-checksum can run the query for you to

make it even easier. See CONSISTENT

CHECKSUMS

for details.

If you find tables that have differences, you can use the chunk

boundaries in a

WHERE clause with mk-table-sync

to help repair them more

efficiently

. See

mk-table-sync

for details.

The table must have at least these columns: db, tbl, chunk,

boundaries,

this_crc, master_crc, this_cnt, master_cnt. The table may be named

anything you

wish. Here is a suggested table structure, which is automatically used

for

--create-replicate-table

(MAGIC_create_replicate):

CREATE TABLE checksum (

db char(64) NOT NULL,

tbl char(64) NOT NULL,

chunk int NOT NULL,

boundaries char(100) NOT NULL,

this_crc char(40) NOT NULL,

this_cnt int NOT NULL,

master_crc char(40) NULL,

master_cnt int NULL,

ts timestamp NOT NULL,

PRIMARY KEY (db, tbl, chunk)

);

Be sure to choose an appropriate storage engine for the checksum

table. If you

are checksumming InnoDB tables, for instance, a deadlock will break

replication

if the checksum table is non-transactional, because the transaction will

still

be written to the binlog. It will then replay without a deadlock on the

slave and break replication with "different error on master and slave."

This

is not a problem with mk-table-checksum, it's a problem with MySQL

replication, and you can read more about it in the MySQL manual.

This works only with statement-based replication (mk-table-checksum

will switch

the binlog format to STATEMENT for the duration of the session if your

server

uses row-based replication)

.

In contrast to running the tool against multiple servers at once,

using this

option eliminates the complexities of synchronizing checksum queries

across

multiple servers, which normally requires locking and unlocking, waiting

for

master binlog positions, and so on. Thus, it disables --lock

,

--wait

,

and --slave-lag

(but not --check-slave-lag

,

which is a way to throttle

the execution speed).

The checksum queries actually do a REPLACE into this table, so

existing rows

need not be removed before running. However, you may wish to do this

anyway to

remove rows related to tables that don't exist anymore. The

--empty-replicate-table

option does this for you.

Since mk-table-checksum uses USE to select the table's database as

its

default database before executing the checksum query, the checksum

queries

should replicate to slaves even if --binlog-do-db settings on the master

filter

out the checksum table's database.

For more information on how

--binlog-do-db

works, see http://dev.mysql.com/doc/en/binary-log.html

.

If the slaves have any --replicate-do-X or --replicate-ignore-X

options, you

should be careful not to checksum any databases or tables that exist on

the

master and not the slaves.

Changes to such tables may not normally be

executed

on the slaves because of the --replicate options, but the checksum

queries

modify the contents of the table that stores the checksums, not the

tables whose

data you are checksumming. Therefore, these queries will be executed on

the

slave, and if the table or database you're checksumming does not exist,

the

queries will cause replication to fail. For more information on

replication

rules, see http://dev.mysql.com/doc/en/replication-rules.html

.

The table specified by --replicate

will never be checksummed itself.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您解答关于SpringBoot和ShardingSphere实现读写分离的问题。 首先,您需要在pom.xml文件中添加ShardingSphere相关依赖: ```xml <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>sharding-jdbc-core</artifactId> <version>${sharding-sphere.version}</version> </dependency> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>sharding-jdbc-spring-boot-starter</artifactId> <version>${sharding-sphere.version}</version> </dependency> ``` 其中${sharding-sphere.version}为ShardingSphere的版本号。 接下来,您需要在application.yml或application.properties中配置ShardingSphere的数据源和规则,例如: ```yaml spring: shardingsphere: datasource: names: ds_master, ds_slave_0, ds_slave_1 ds_master: url: jdbc:mysql://localhost:3306/mydb_master?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 username: root password: root ds_slave_0: url: jdbc:mysql://localhost:3306/mydb_slave_0?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 username: root password: root ds_slave_1: url: jdbc:mysql://localhost:3306/mydb_slave_1?useSSL=false&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 username: root password: root sharding: default-data-source-name: ds_master master-slave-rules: ds_0: master-data-source-name: ds_master slave-data-source-names: ds_slave_0, ds_slave_1 load-balance-algorithm-type: round_robin ``` 以上配置中,我们配置了3个数据源:ds_master, ds_slave_0和ds_slave_1,其中ds_master为主库,ds_slave_0和ds_slave_1为从库。然后我们使用了ShardingSphere提供的master-slave规则将ds_master和ds_slave_0、ds_slave_1进行了关联,并使用了轮询算法进行负载均衡,从而实现了读写分离。 最后,您需要在SpringBoot主类上添加@EnableSharding注解,以启用ShardingSphere的功能。 这就是使用SpringBoot和ShardingSphere实现读写分离的基本步骤。希望对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值