- 浏览: 96839 次
- 性别:
- 来自: 上海
-
最新评论
-
zdx3578:
rsync -avrlptzon s d
zabbix编译: -
zdx3578:
jmx hostname -i 确认机器名!
优化杂记 -
zdx3578:
http://www.linuxyw.com/a/WEBfuw ...
通过证书dn名映射应用其他的登录名 -
zdx3578:
http://www.cnblogs.com/peida/ta ...
vmstat system in cs cs: The number of context switches per second. 高 -
zdx3578:
cmdb2.1.7 + shark workflow 安装ok ...
cmdbuild
mysql 同步工具 mk-table-sync
google和javaeye都很牛叉哈!
- NAME
- SYNOPSIS
- RISKS
- DESCRIPTION
- OUTPUT
- REPLICATION SAFETY
- ALGORITHMS
- BIDIRECTIONAL SYNCING
- EXIT STATUS
- OPTIONS
- DSN OPTIONS
- DOWNLOADING
- ENVIRONMENT
- SYSTEM REQUIREMENTS
- BUGS
- COPYRIGHT, LICENSE AND WARRANTY
- AUTHOR
- ABOUT MAATKIT
- HISTORY AND ACKNOWLEDGEMENTS
- VERSION
NAME
mk-table-sync - Synchronize MySQL tables efficiently. 同步mysql表
SYNOPSIS
This tool changes data, so for maximum safety, you should back up your data before you use it. 为安全最好先备份数据
To sync db.tbl1 from host1 to host2: 机器1 to 2
mk-table-sync --execute u=user,p=pass,h=host1,D=db,t=tbl host2
Sync all tables in host1 to host2 and host3:
mk-table-sync --execute host1 host2 host3
Resolve differences mk-table-checksum found on this master's slaves:
mk-table-sync --execute --replicate test.checksum master1
Make slave1 have the same data as its replication master:
mk-table-sync --execute --sync-to-master slave1
Ditto, resolving differences mk-table-checksum found:
mk-table-sync --execute --sync-to-master \ --replicate test.checksum slave1
Sync server2 in a master-master replication configuration, where server2's copy of db1.tbl1 is known or suspected to be incorrect:
mk-table-sync --execute --sync-to-master h=server2,D=db1,t=tbl1
Note that in the master-master configuration, the following will NOT do what you want, because it will make changes directly on server2, which will then flow through replication and change server1's data:
# Don't do this in a master-master setup! mk-table-sync --execute h=server1,D=db1,t=tbl1 h=server2
RISKS
The following section is included to inform users about the potential risks, whether known or unknown, of using this tool. The two main categories of risks are those created by the nature of the tool (e.g. read-only tools vs. read-write tools) and those created by bugs.
With great power comes great responsibility! This tool changes data, so it is a good idea to back up your data. It is also very powerful, which means it is very complex, so you should run it with the --dry-run option to see what it will do, until you're familiar with its operation. If you want to see which rows are different, without changing any data, use --print instead of --execute .
Be careful when using mk-table-sync in any master-master setup . Master-master replication is inherently tricky, and it's easy to make mistakes. Yyou need to be sure you're using the tool correctly for master-master replication. See the SYNOPSIS for the overview of the correct usage.
In general, this tool is best suited when your tables have a primary key or unique index . Although it can synchronize data in tables lacking a primary key or unique index, it might be best to sychronize that data by another means.
At the time of this release, there is a potential bug using
--lock-and-rename
with MySQL 5.1,
a bug detecting certain differences,
a bug using ROUND()
across different platforms, a bug
mixing collations,
and a bug chunking inside mk-table-checksum boundaries.
The authoritative source for updated information is always the online issue tracking system. Issues that affect this tool will be marked as such. You can see a list of such issues at the following URL: http://www.maatkit.org/bugs/mk-table-sync .
See also BUGS for more information on filing bugs and getting help.
DESCRIPTION
WARNING this tool is unfinished and could perform slowly. The Chunk algorithm is great when it can be used, and so is Nibble, but otherwise GroupBy is the default choice and it may not perform very well. Please run with --dry-run before subjecting your servers to this tool, and make backups of your data!
This tool is designed to do one-way and bidirectional synchronization of data. It finds differences efficiently with one of several algorithms (see ALGORITHMS ). It makes changes on the destination table(s) so it matches the source.
It does not synchronize table structures, indexes, or any other schema changes . It synchronizes only data.
It can operate through replication by comparing a slave with its master and making changes on the master . These changes will flow through replication and correct any differences found on the slave.
It accepts a list of DSNs (see the --help output) to tell it where and how to connect.
There are many ways to invoke it. The following is the abbreviated logic:
if DSN has a t part, sync only that table:
if 1 DSN:
if --sync-to-master:
The DSN is a slave. Connect to its master and sync.
if more than 1 DSN:
The first DSN is the source. Sync each DSN in turn.
else if --replicate:
if --sync-to-master:
The DSN is a slave. Connect to its master, find records
of differences, and fix.
else:
The DSN is the master. Find slaves and connect to each,
find records of differences, and fix.
else:
if only 1 DSN and --sync-to-master:
The DSN is a slave. Connect to its master, find tables and
filter with --databases etc, and sync each table to the master.
else:
find tables, filtering with --databases etc, and sync each
DSN to the first.
If you're confused about how it the DSNs are interpreted, use the --explain-hosts option and it will tell you.
OUTPUT
If you specify the --verbose option, you'll see information about the differences between the tables. There is one row per table. Each server is printed separately. For example,
# Syncing h=host1,D=test,t=test1 # DELETE REPLACE INSERT UPDATE ALGORITHM EXIT DATABASE.TABLE # 0 0 3 0 Chunk 2 test.test1
Table test.test1 on host1 required 3 INSERT
statements
to synchronize
and it used the Chunk algorithm (see ALGORITHMS
).
Because differences were
found, its EXIT
STATUS
was 2.
If you specify the --print option, you'll see the actual SQL statements that the script uses to synchronize the table if --execute is also specified.
If you want to see t he SQL statements that mk-table-sync is using to select chunks, nibbles, rows, etc., then specify --print once and --verbose twice . Be careful though: this can print a lot of SQL statements.
There are cases where no combination of INSERT
, UPDATE
or DELETE
statements can resolve differences without violating some unique key.
For
example, suppose there's a primary key on column a and a unique key on
column b.
Then there is no way to sync these two tables with straightforward
UPDATE
statements:
+---+---+ +---+---+ | a | b | | a | b | +---+---+ +---+---+ | 1 | 2 | | 1 | 1 | | 2 | 1 | | 2 | 2 | +---+---+ +---+---+
The tool rewrites queries to DELETE
and REPLACE
in this case. This is
automatically handled after the first index violation, so you don't have
to
worry about it.
REPLICATION SAFETY
Synchronizing a replication master and slave safely is a non-trivial problem, in general. There are all sorts of issues to think about, such as other processes changing data, trying to change data on the slave, whether the destination and source are a master-master pair, and much more.
In general, the safe way to do it is to change the data on the master , and let the changes flow through replication to the slave like any other changes. However, this works only if it's possible to REPLACE into the table on the master. REPLACE works only if there's a unique index on the table (otherwise it just acts like an ordinary INSERT).
If your table has unique keys,
you should use the --sync-to-master
and/or
--replicate
options to sync a slave to its master. This will generally do
the right thing. When there is no unique key
on the table, there is no
choice
but to change the data on the slave, and mk-table-sync will detect that
you're
trying to do so. It will complain and die unless you specify
--no-check-slave
(see --[no]check-slave
).
If you're syncing a table without a primary or unique key on a
master-master
pair, you must change the data on the destination server. Therefore,
you need
to specify --no-bin-log
for safety (see --[no]bin-log
).
If you don't,
the changes you make on the destination server will replicate back to
the
source server and change the data there!
The generally safe thing to do on a master-master pair is to use the
--sync-to-master
option so you don't change the data on the destination
server. You will also need to specify --no-check-slave
to keep
mk-table-sync from complaining that it is changing data on a slave.
ALGORITHMS
This tool has a generic data-syncing framework, within which it is possible to use any number of different algorithms to actually find differences . It chooses the best algorithm automatically . While I plan to add more algorithms in the future, the following are implemented now:
Finds an index whose first column is numeric (including date and time types), and divides the column's range of values into chunks of approximately --chunk-size rows. Syncs a chunk at a time by checksumming the entire chunk. If the chunk differs on the source and destination, checksums each chunk's rows individually to find the rows that differ .
It is efficient when the column has sufficient cardinality to make the chunks end up about the right size.
The initial per-chunk checksum is quite small and results in minimal network traffic and memory consumption. If a chunk's rows must be examined, only the primary key columns and a checksum are sent over the network, not the entire row. If a row is found to be different, the entire row will be fetched, but not before. 和rsync类似哦,都是先检查checksum是否一致再判断是否需要进一步比较
Finds an index and ascends the index in fixed-size nibbles of --chunk-size
rows, using a non-backtracking algorithm (see mk-archiver
for
more on this
algorithm). It is very similar to Chunk
,
but instead of pre-calculating
the boundaries of each piece of the table based on index cardinality, it
uses
LIMIT
to define each nibble's upper limit, and the previous
nibble's upper
limit to define the lower limit.
It works in steps: one query finds the row that will define the next nibble's upper boundary, and the next query checksums the entire nibble. If the nibble differs between the source and destination, it examines the nibble row-by-row, just as Chunk does.
Selects the entire table grouped by all columns, with a COUNT(*) column added. Compares all columns, and if they're the same, compares the COUNT(*) column's value to determine how many rows to insert or delete into the destination. Works on tables with no primary key or unique index .
Selects the entire table in one big stream and compares all columns. Selects all columns. Much less efficient than the other algorithms, but works when there is no suitable index for them to use .
Possibilities for future algorithms are TempTable (what I originally called bottom-up in earlier versions of this tool), DrillDown (what I originallly called top-down), and GroupByPrefix (similar to how SqlYOG Job Agent works). Each algorithm has strengths and weaknesses. If you'd like to implement your favorite technique for finding differences between two sources of data on possibly different servers, I'm willing to help. The algorithms adhere to a simple interface that makes it pretty easy to write your own.
BIDIRECTIONAL SYNCING
Bidirectional syncing is a new, experimental feature. To make it work reliably there are a number of strict limitations:
* only works when syncing one server to other independent servers * does not work in any way with replication * requires that the table(s) are chunkable with the Chunk algorithm * is not N-way, only bidirectional between two servers at a time * does not handle DELETE changes
For example, suppose we have three servers: c1, r1, r2. c1 is the central server, a pseudo-master to the other servers (viz. r1 and r2 are not slaves to c1). r1 and r2 are remote servers. Rows in table foo are updated and inserted on all three servers and we want to synchronize all the changes between all the servers. Table foo has columns:
id int PRIMARY KEY ts timestamp auto updated name varchar
Auto-increment offsets are used so that new rows from any server do not create conflicting primary key (id) values. In general, newer rows, as determined by the ts column, take precedence when a same but differing row is found during the bidirectional sync. "Same but differing" means that two rows have the same primary key (id) value but different values for some other column, like the name column in this example. Same but differing conflicts are resolved by a "conflict". A conflict compares some column of the competing rows to determine a "winner". The winnning row becomes the source and its values are used to update the other row.
There are subtle differences between three columns used to achieve
bidirectional syncing that you should be familiar with: chunk column
(--chunk-column
),
comparison column(s) (--columns
),
and conflict
column (--conflict-column
).
The chunk column is only used to chunk the
table; e.g. "WHERE id >= 5 AND id < 10". Chunks are checksummed
and when
chunk checksums reveal a difference, the tool selects the rows in that
chunk and checksums the --columns
for each row. If a column checksum
differs, the rows have one or more conflicting column values. In a
traditional unidirectional sync, the conflict is a moot point because it
can
be resolved simply by updating the entire destination row with the
source
row's values. In a bidirectional sync, however, the --conflict-column
(in accordance with other --conflict-*
options list below)
is compared
to determine which row is "correct" or "authoritative"; this row becomes
the "source".
To sync all three servers completely, two runs of mk-table-sync are required. The first run syncs c1 and r1, then syncs c1 and r2 including any changes from r1. At this point c1 and r2 are completely in sync, but r1 is missing any changes from r2 because c1 didn't have these changes when it and r1 were synced. So a second run is needed which syncs the servers in the same order, but this time when c1 and r1 are synced r1 gets r2's changes.
The tool does not sync N-ways, only bidirectionally between the first DSN given on the command line and each subsequent DSN in turn. So the tool in this example would be ran twice like:
mk-table-sync --bidirectional h=c1 h=r1 h=r2
The --bidirectional option enables this feature and causes various sanity checks to be performed. You must specify other options that tell mk-table-sync how to resolve conflicts for same but differing rows. These options are:
* L<--conflict-column> * L<--conflict-comparison> * L<--conflict-value> * L<--conflict-threshold> * L<--conflict-error> (optional)
Use --print to test this option before --execute . The printed SQL statements will have comments saying on which host the statment would be executed if you used --execute .
Technical side note: the first DSN is always the "left" server and the other DSNs are always the "right" server. Since either server can become the source or destination it's confusing to think of them as "src" and "dst". Therefore, they're generically referred to as left and right. It's easy to remember this because the first DSN is always to the left of the other server DSNs on the command line.
EXIT STATUS
Exit status is as follows:
STATUS MEANING ====== ======================================================= 0 Success. 1 Internal error. 2 At least one table differed on the destination. 3 Combination of 1 and 2.
OPTIONS
Specify at least one of --print
, --execute
,
or --dry-run
.dry-run 不执行!
--where and --replicate are mutually exclusive.
type: string; default: Chunk,Nibble,GroupBy,Stream
Algorithm to use when comparing the tables, in order of preference.
For each table, mk-table-sync will check if the table can be synced with the given algorithms in the order that they're given. The first algorithm that can sync the table is used. See ALGORITHMS .
Prompt for a password when connecting to MySQL.
Enable bidirectional sync between first and subsequent hosts.
See BIDIRECTIONAL SYNCING for more information.
default: yes
Log to the binary log (SET SQL_LOG_BIN=1
).
Specifying --no-bin-log
will SET SQL_LOG_BIN=0
.
Instruct MySQL to buffer queries in its memory.
This option adds the SQL_BUFFER_RESULT
option to the
comparison queries.
This causes MySQL to execute the queries and place them in a temporary
table
internally before sending the results back to mk-table-sync. The
advantage of
this strategy is that mk-table-sync can fetch rows as desired without
using a
lot of memory inside the Perl process, while releasing locks on the
MySQL table
(to reduce contention with other queries). The disadvantage is that it
uses
more memory on the MySQL server instead.
You probably want to leave --[no]buffer-to-client enabled too, because buffering into a temp table and then fetching it all into Perl's memory is probably a silly thing to do. This option is most useful for the GroupBy and Stream algorithms, which may fetch a lot of data from the server.
default: yes
Fetch rows one-by-one from MySQL while comparing.
This is disabled by default. If enabled, all rows will be fetched into memory for comparing. This may result in the results "cursor" being held open for a shorter time on the server, but if the tables are large, it could take a long time anyway, and eat all your memory. For most non-trivial data sizes, you want to leave this disabled.
short form: -A; type: string
Default character set. If the value is utf8, sets Perl's binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL.
default: yes
With --sync-to-master , try to verify that the detected master is the real master.
default: yes
Check that user has all necessary privileges on source and destination table.
default: yes
Check whether the destination server is a slave.
If the destination server is a slave, it's generally unsafe to make
changes on
it. However, sometimes you have to; --replace
won't work unless there's a
unique index, for example, so you can't make changes on the master in
that
scenario. By default mk-table-sync will complain if you try to change
data on
a slave. Specify --no-slave-check
to disable this check.
Use it at your own
risk.
default: yes
Check that no triggers are defined on the destination table.
Triggers were introduced in MySQL v5.0.2, so for older versions this option has no effect because triggers will not be checked.
type: string
Chunk the table on this column.
type: string
Chunk the table using this index.
type: string; default: 1000
Number of rows or data size per chunk.
The size of each chunk of rows for the Chunk and Nibble algorithms. The size can be either a number of rows, or a data size. Data sizes are specified with a suffix of k=kibibytes, M=mebibytes, G=gibibytes. Data sizes are converted to a number of rows by dividing by the average row length.
short form: -c; type: array
Compare this comma-separated list of columns.
type: Array
Read this comma-separated list of config files; if specified, this must be the first option on the command line.
type: string
Compare this column when rows conflict during a --bidirectional sync.
When a same but differing row is found the value of this column from each row is compared according to --conflict-comparison , --conflict-value and --conflict-threshold to determine which row has the correct data and becomes the source. The column can be any type for which there is an appropriate --conflict-comparison (this is almost all types except, for example, blobs).
This option only works with --bidirectional . See BIDIRECTIONAL SYNCING for more information.
type: string
Choose the --conflict-column with this property as the source.
The option affects how the --conflict-column values from the conflicting rows are compared. Possible comparisons are one of these MAGIC_comparisons:
newest|oldest|greatest|least|equals|matches
COMPARISON CHOOSES ROW WITH ========== ========================================================= newest Newest temporal L<--conflict-column> value oldest Oldest temporal L<--conflict-column> value greatest Greatest numerical L<--conflict-column> value least Least numerical L<--conflict-column> value equals L<--conflict-column> value equal to L<--conflict-value> matches L<--conflict-column> value matching Perl regex pattern L<--conflict-value>
This option only works with --bidirectional . See BIDIRECTIONAL SYNCING for more information.
type: string; default: warn
How to report unresolvable conflicts and conflict errors
This option changes how the user is notified when a conflict cannot be resolved or causes some kind of error. Possible values are:
* warn: Print a warning to STDERR about the unresolvable conflict * die: Die, stop syncing, and print a warning to STDERR
This option only works with --bidirectional . See BIDIRECTIONAL SYNCING for more information.
type: string
Amount by which one --conflict-column must exceed the other.
The --conflict-threshold prevents a conflict from being resolved if the absolute difference between the two --conflict-column values is less than this amount. For example, if two --conflict-column have timestamp values "2009-12-01 12:00:00" and "2009-12-01 12:05:00" the difference is 5 minutes. If --conflict-threshold is set to "5m" the conflict will be resolved, but if --conflict-threshold is set to "6m" the conflict will fail to resolve because the difference is not greater than or equal to 6 minutes. In this latter case, --conflict-error will report the failure.
This option only works with --bidirectional . See BIDIRECTIONAL SYNCING for more information.
type: string
Use this value for certain --conflict-comparison .
This option gives the value for equals
and matches
--conflict-comparison
.
This option only works with --bidirectional . See BIDIRECTIONAL SYNCING for more information.
short form: -d; type: hash
Sync only this comma-separated list of databases.
A common request is to sync tables from one database with tables from another database on the same or different server. This is not yet possible. --databases will not do it, and you can't do it with the D part of the DSN either because in the absence of a table name it assumes the whole server should be synced and the D part controls only the connection's default database.
short form: -F; type: string
Only read mysql options from the given file. You must give an absolute pathname.
Analyze, decide the sync algorithm to use, print and exit.
Implies --verbose so you can see the results. The results are in the same output format that you'll see from actually running the tool, but there will be zeros for rows affected. This is because the tool actually executes, but stops before it compares any data and just returns zeros. The zeros do not mean there are no changes to be made.
short form: -e; type: hash
Sync only this comma-separated list of storage engines.
Execute queries to make the tables have identical data.
This option makes mk-table-sync actually sync table data by executing all the queries that it created to resolve table differences. Therefore, the tables will be changed! And unless you also specify --verbose , the changes will be made silently. If this is not what you want, see --print or --dry-run .
Print connection information and exit.
Print out a list of hosts to which mk-table-sync will connect, with all the various connection options, and exit.
type: int
Precision for FLOAT
and DOUBLE
column
comparisons.
If you specify this option, FLOAT and DOUBLE columns will be rounded to the specified number of digits after the decimal point for the checksum. This can avoid mismatches due to different floating-point representations of the same values on different MySQL versions and hardware.
default: yes
Enable foreign key checks (SET FOREIGN_KEY_CHECKS=1
).
Specifying --no-foreign-key-checks
will SET FOREIGN_KEY_CHECKS=0
.
type: string
Which hash function you'd like to use for checksums.
The default is CRC32
. Other good choices include MD5
and SHA1
. If you
have installed the FNV_64
user-defined function, mk-table-sync
will detect
it and prefer to use it, because it is much faster than the built-ins.
You can
also use MURMUR_HASH if you've installed that user-defined function.
Both of
these are distributed with Maatkit. See mk-table-checksum
for
more
information and benchmarks.
Show help and exit.
default: yes
HEX()
BLOB
, TEXT
and BINARY
columns.
When row data from the source is fetched to create queries to sync
the
data (i.e. the queries seen with --print
and exeucted by --execute
),
binary
columns are wrapped in HEX()
so the binary data does not
produce
an invalid SQL statement. You can disable this option but you probably
shouldn't.
short form: -h; type: string
Connect to host.
type: Hash
Ignore this comma-separated list of column names in comparisons.
This option causes columns not to be compared. However, if a row is determined to differ between tables, all columns in that row will be synced, regardless. (It is not currently possible to exclude columns from the sync process itself, only from the comparison.)
type: Hash
Ignore this comma-separated list of databases.
type: Hash; default: FEDERATED,MRG_MyISAM
Ignore this comma-separated list of storage engines.
type: Hash
Ignore this comma-separated list of tables.
Table names may be qualified with the database name.
default: yes
Add FORCE/USE INDEX hints to the chunk and row queries.
By default mk-table-sync
adds a FORCE/USE INDEX hint to
each SQL statement
to coerce MySQL into using the index chosen by the sync algorithm or
specified
by --chunk-index
.
This is usually a good thing, but in rare cases the
index may not be the best for the query so you can suppress the index
hint
by specifying --no-index-hint
and let MySQL choose the index.
This does not affect the queries printed by --print
;
it only affects the
chunk and row queries that mk-table-sync
uses to select and
compare rows.
type: int
Lock tables: 0=none, 1=per sync cycle, 2=per table, or 3=globally.
This uses LOCK TABLES
. This can help prevent tables
being changed while
you're examining them. The possible values are as follows:
VALUE MEANING ===== ======================================================= 0 Never lock tables. 1 Lock and unlock one time per sync cycle (as implemented by the syncing algorithm). This is the most granular level of locking available. For example, the Chunk algorithm will lock each chunk of C<N> rows, and then unlock them if they are the same on the source and the destination, before moving on to the next chunk. 2 Lock and unlock before and after each table. 3 Lock and unlock once for every server (DSN) synced, with C<FLUSH TABLES WITH READ LOCK>.
A replication slave is never locked if --replicate or --sync-to-master is specified, since in theory locking the table on the master should prevent any changes from taking place. (You are not changing data on your slave, right?) If --wait is given, the master (source) is locked and then the tool waits for the slave to catch up to the master before continuing.
If --transaction
is specified, LOCK TABLES
is not used. Instead, lock
and unlock are implemented by beginning and committing transactions.
The exception is if --lock
is
3.
If --no-transaction
is specified, then LOCK TABLES
is used for any
value of --lock
.
See --[no]transaction
.
Lock the source and destination table, sync, then swap names. This is useful as a less-blocking ALTER TABLE, once the tables are reasonably in sync with each other (which you may choose to accomplish via any number of means, including dump and reload or even something like mk-archiver ). It requires exactly two DSNs and assumes they are on the same server, so it does no waiting for replication or the like. Tables are locked with LOCK TABLES.
short form: -p; type: string
Password to use when connecting.
type: string
Create the given PID file. The file contains the process ID of the script. The PID file is removed when the script exits. Before starting, the script checks if the PID file already exists. If it does not, then the script creates and writes its own PID to it. If it does, then the script checks the following: if the file contains a PID and a process is running with that PID, then the script dies; or, if there is no process running with that PID, then the script overwrites the file with its own PID and starts; else, if the file contains no PID, then the script dies.
short form: -P; type: int
Port number to use for connection.
Print queries that will resolve differences.
If you don't trust mk-table-sync
, or just want to see
what it will do, this
is a good way to be safe. These queries are valid SQL and you can run
them
yourself if you want to sync the tables manually.
type: string
Preferred recursion method used to find slaves.
Possible methods are:
METHOD USES =========== ================ processlist SHOW PROCESSLIST hosts SHOW SLAVE HOSTS
The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. However, the hosts method is required if the server uses a non-standard port (not 3306). Usually mk-table-sync does the right thing and finds the slaves, but you may give a preferred method and it will be used first. If it doesn't find any slaves, the other methods will be tried.
Write all INSERT
and UPDATE
statements as REPLACE
.
This is automatically switched on as needed when there are unique index violations.
type: string
Sync tables listed as different in this table.
Specifies that mk-table-sync
should examine the
specified table to find data
that differs. The table is exactly the same as the argument of the same
name to
mk-table-checksum
. That is, it contains records of which
tables (and ranges
of values) differ between the master and slave.
For each table and range of values that shows differences between the
master and
slave, mk-table-checksum
will sync that table, with the
appropriate WHERE
clause, to its master.
This automatically sets --wait to 60 and causes changes to be made on the master instead of the slave.
If --sync-to-master is specified, the tool will assume the server you specified is the slave, and connect to the master as usual to sync.
Otherwise, it will try to use SHOW PROCESSLIST
to find
slaves of the server
you specified. If it is unable to find any slaves via SHOW
PROCESSLIST
, it
will inspect SHOW SLAVE HOSTS
instead. You must configure
each slave's
report-host
, report-port
and other options for
this to work right. After
finding slaves, it will inspect the specified table on each slave to
find data
that needs to be synced, and sync it.
The tool examines the master's copy of the table first, assuming that
the master
is potentially a slave as well. Any table that shows differences there
will
NOT
be synced on the slave(s). For example, suppose
your replication is set
up as A->B, B->C, B->D. Suppose you use this argument and
specify server B.
The tool will examine server B's copy of the table. If it looks like
server B's
data in table test.tbl1
is different from server A's copy,
the tool will not
sync that table on servers C and D.
type: string; default: wait_timeout=10000
Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
short form: -S; type: string
Socket file to use for connection.
Treat the DSN as a slave and sync it to its master.
Treat the server you specified as a slave. Inspect SHOW SLAVE
STATUS
,
connect to the server's master, and treat the master as the source and
the slave
as the destination. Causes changes to be made on the master. Sets --wait
to 60 by default, sets --lock
to 1
by default, and disables
--[no]transaction
by default. See also --replicate
,
which changes
this option's behavior.
short form: -t; type: hash
Sync only this comma-separated list of tables.
Table names may be qualified with the database name.
Keep going if --wait fails.
If you specify --wait and the slave doesn't catch up to the master's position before the wait times out, the default behavior is to abort. This option makes the tool keep going anyway. Warning : if you are trying to get a consistent comparision between the two servers, you probably don't want to keep going after a timeout.
Use transactions instead of LOCK TABLES
.
The granularity of beginning and committing transactions is controlled by --lock . This is enabled by default, but since --lock is disabled by default, it has no effect.
Most options that enable locking also disable transactions by
default, so if
you want to use transactional locking (via LOCK IN SHARE MODE
and FOR
UPDATE
, you must specify --transaction
explicitly.
If you don't specify --transaction
explicitly mk-table-sync
will decide on
a per-table basis whether to use transactions or table locks. It
currently
uses transactions on InnoDB tables, and table locks on all others.
If --no-transaction
is specified, then mk-table-sync
will not use
transactions at all (not even for InnoDB tables) and locking is
controlled
by --lock
.
TRIM()
VARCHAR
columns in BIT_XOR
and ACCUM
modes. Helps when
comparing MySQL 4.1 to >= 5.0.
This is useful when you don't care about the trailing space
differences between
MySQL versions which vary in their handling of trailing spaces. MySQL
5.0 and
later all retain trailing spaces in VARCHAR
, while previous
versions would
remove them.
default: yes
Enable unique key checks (SET UNIQUE_CHECKS=1
).
Specifying --no-unique-checks
will SET UNIQUE_CHECKS=0
.
short form: -u; type: string
User for login if not current user.
short form: -v; cumulative: yes
Print results of sync operations.
See OUTPUT for more details about the output.
Show version and exit.
short form: -w; type: time
How long to wait for slaves to catch up to their master.
Make the master wait for the slave to catch up in replication before comparing the tables. The value is the number of seconds to wait before timing out (see also --timeout-ok ). Sets --lock to 1 and --[no]transaction to 0 by default. If you see an error such as the following,
MASTER_POS_WAIT returned -1
It means the timeout was exceeded and you need to increase it.
The default value of this option is influenced by other options. To see what value is in effect, run with --help .
type: string
WHERE
clause to restrict syncing to part of the table.
DSN OPTIONS
These DSN options are used to create a DSN. Each option is given
like
option=value
. The options are case-sensitive, so P and p
are not the
same option. There cannot be whitespace before or after the =
and
if the value contains whitespace it must be quoted. DSN options are
comma-separated. See the maatkit
manpage for full details.
-
A
dsn: charset; copy: yes
Default character set.
-
D
dsn: database; copy: yes
Database containing the table to be synced.
-
F
dsn: mysql_read_default_file; copy: yes
Only read default options from the given file
-
h
dsn: host; copy: yes
Connect to host.
-
p
dsn: password; copy: yes
Password to use when connecting.
-
P
dsn: port; copy: yes
Port number to use for connection.
-
S
dsn: mysql_socket; copy: yes
Socket file to use for connection.
-
t
copy: yes
Table to be synced.
-
u
dsn: user; copy: yes
User for login if not current user.
DOWNLOADING
You can download Maatkit from Google Code at http://code.google.com/p/maatkit/ , or you can get any of the tools easily with a command like the following:
wget http://www.maatkit.org/get/toolname or wget http://www.maatkit.org/trunk/toolname
Where toolname
can be replaced with the name (or
fragment of a name) of any
of the Maatkit tools. Once downloaded, they're ready to run; no
installation is
needed. The first URL gets the latest released version of the tool, and
the
second gets the latest trunk code from Subversion.
ENVIRONMENT
The environment variable MKDEBUG enables verbose debugging output in all of the Maatkit tools:
MKDEBUG=1 mk-....
SYSTEM REQUIREMENTS
You need Perl, DBI, DBD::mysql, and some core packages that ought to be installed in any reasonably new version of Perl.
BUGS
For a list of known bugs see: http://www.maatkit.org/bugs/mk-table-sync .
Please use Google Code Issues and Groups to report bugs or request support: http://code.google.com/p/maatkit/ . You can also join #maatkit on Freenode to discuss Maatkit.
Please include the complete command-line used to reproduce the
problem you are
seeing, the version of all MySQL servers involved, the complete output
of the
tool when run with --version
,
and if possible, debugging output produced by
running with the MKDEBUG=1
environment variable.
COPYRIGHT, LICENSE AND WARRANTY
This program is copyright 2007-2010 Baron Schwartz. Feedback and improvements are welcome.
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License. On UNIX and similar systems, you can issue `man perlgpl' or `man perlartistic' to read these licenses.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
AUTHOR
Baron Schwartz
ABOUT MAATKIT
This tool is part of Maatkit, a toolkit for power users of MySQL. Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the primary code contributors. Both are employed by Percona. Financial support for Maatkit development is primarily provided by Percona and its clients.
HISTORY AND ACKNOWLEDGEMENTS
My work is based in part on Giuseppe Maxia's work on distributed databases, http://www.sysadminmag.com/articles/2004/0408/ and code derived from that article. There is more explanation, and a link to the code, at http://www.perlmonks.org/ .
Another programmer extended Maxia's work even further. Fabien Coelho changed and generalized Maxia's technique, introducing symmetry and avoiding some problems that might have caused too-frequent checksum collisions. This work grew into pg_comparator, http://www.coelho.net/pg_comparator/ . Coelho also explained the technique further in a paper titled "Remote Comparison of Database Tables" (http://cri.ensmp.fr/classement/doc/A-375.pdf ).
This existing literature mostly addressed how to find the differences between the tables, not how to resolve them once found. I needed a tool that would not only find them efficiently, but would then resolve them. I first began thinking about how to improve the technique further with my article http://tinyurl.com/mysql-data-diff-algorithm , where I discussed a number of problems with the Maxia/Coelho "bottom-up" algorithm. After writing that article, I began to write this tool. I wanted to actually implement their algorithm with some improvements so I was sure I understood it completely. I discovered it is not what I thought it was, and is considerably more complex than it appeared to me at first. Fabien Coelho was kind enough to address some questions over email.
The first versions of this tool implemented a version of the Coelho/Maxia algorithm, which I called "bottom-up", and my own, which I called "top-down." Those algorithms are considerably more complex than the current algorithms and I have removed them from this tool, and may add them back later. The improvements to the bottom-up algorithm are my original work, as is the top-down algorithm. The techniques to actually resolve the differences are also my own work.
Another tool that can synchronize tables is the SQLyog Job Agent from webyog. Thanks to Rohit Nadhani, SJA's author, for the conversations about the general techniques. There is a comparison of mk-table-sync and SJA at http://tinyurl.com/maatkit-vs-sqlyog
Thanks to the following people and organizations for helping in many ways:
The Rimm-Kaufman Group http://www.rimmkaufman.com/ , MySQL AB http://www.mysql.com/ , Blue Ridge InternetWorks http://www.briworks.com/ , Percona http://www.percona.com/ , Fabien Coelho, Giuseppe Maxia and others at MySQL AB, Kristian Koehntopp (MySQL AB), Rohit Nadhani
相关推荐
2. mk-table-sync:当数据不一致时,该工具可以帮助快速同步表,无需从头开始重载,减少服务中断时间。 3. mk-visual-explain:增强版的EXPLAIN,提供更直观的查询计划解析,便于理解查询的执行路径。 4. mk-...
拖拉机变速箱箱体工艺及夹具设计.rar
birch_door_bottom
台灯底座塑料模设计.rar
塑料瓶自动封口机(自动容器封口机)设计.rar
液压电梯与立体车库的组合设计.rar
barrel_top_open
activator_rail
内容概要:本文介绍了计算机专业毕业设计的选题方向,涵盖软件开发、人工智能、数据分析、网络安全四大领域。在软件开发类中,包括基于Spring Boot和Vue.js的在线教育平台、基于Android的健身管理APP、企业资源规划(ERP)系统等;人工智能类涉及基于深度学习的图像识别垃圾分类系统、智能客服系统、机器人路径规划算法等;数据分析类则关注电商平台用户行为分析、医疗大数据分析、社交媒体舆情分析;网络安全类有基于入侵检测系统的网络安全防护体系、云存储数据安全加密与访问控制、无线网络安全漏洞检测与防范系统。每个方向都给出了具体的项目示例,并简述了项目的核心技术和应用场景。; 适合人群:计算机相关专业的本科毕业生,特别是正在准备毕业设计的学生。; 使用场景及目标:帮助学生根据个人兴趣和技术背景选择合适的毕业设计课题,明确研究方向和预期成果,为顺利完成毕业设计提供参考。; 其他说明:毕业设计是学生将理论知识转化为实际应用的重要环节,选题时应充分考虑自身的技术积累和兴趣点,确保项目的可行性和创新性。同时,建议学生在选题过程中积极与导师沟通,获取更多专业指导和支持。
内容概要:本文探讨了三种去除玻璃窗反射的方法及其实验结果。第一种方法是基于平滑性的单图像层分离法,适用于静态图像,假设背景层比反射层更清晰,通过高斯滤波和梯度提取分离两层。第二种方法是基于运动的多帧图像分离法,利用连续拍摄的图像序列,通过边缘检测、稀疏运动场计算、分类、稠密运动场插值和图像变形实现反射与背景分离。第三种方法是基于稀疏先验的用户辅助分离法,需要用户提供反射层和背景层的边缘信息,通过期望最大化(EM)或迭代重加权最小二乘优化(IRLS)算法进行分离。; 适合人群:计算机视觉领域的研究人员、图像处理工程师以及对图像去反射技术感兴趣的开发者。; 使用场景及目标:①从单张照片中去除玻璃窗反射,适用于摄影后期处理;②从连续拍摄的图像序列中去除反射,适用于智能手机和相机的实时图像处理;③通过用户标记辅助去除复杂场景中的反射,适用于特定应用场景下的图像修复。; 其他说明:本文详细介绍了每种方法的算法步骤和实验结果,指出了各方法的优点和局限性。Smoothness Approach适用于简单背景和聚焦良好的图像,Motion Approach需要多帧图像但对普通情况表现良好,User-assisted Separation with Sparse Prior则需要用户干预且内存开销较大。
内容概要:本文档详细介绍了基于SSH(Struts、Spring、Hibernate)框架的医院在线挂号系统的设计与实现。随着互联网技术的发展,传统医院挂号方式因效率低下、耗时等问题亟待改进。该系统旨在解决患者挂号难、排队时间长的问题,通过在线平台提供便捷的预约挂号服务。系统采用SSH框架,结合MySql数据库,确保了系统的稳定性、安全性和易维护性。系统的主要角色包括患者和管理员,患者可以查询医院及医生信息、注册登录、预约挂号、取消挂号、更改个人信息;管理员则负责更新医院和医生信息、发布公告、管理用户信息等。系统设计了导航引导新用户操作,分离了用户和管理员登录入口,确保了系统的易用性和安全性。总体测试结果显示,该网站基本符合用户需求,达到了较高的用户满意度。 适合人群:计算机科学、软件工程及相关专业的本科生或研究生,尤其是对医院信息系统开发感兴趣的读者。 使用场景及目标:①适用于医院信息化建设项目,特别是需要改进挂号流程、提高医疗服务效率的场景;②为开发人员提供一个基于SSH框架的医院在线挂号系统的实现案例,帮助理解SSH框架在实际项目中的应用;③为医院管理层提供一种现代化的挂号管理方案,优化资源配置,提高患者满意度。 其他说明:该系统不仅提高了医院的管理效率和服务质量,也为患者提供了便捷的挂号方式,减少了不必要的等待时间。系统采用的技术栈(SSH框架、MySql数据库等)具有良好的可扩展性和复用性,便于后续功能的扩展和技术升级。此外,系统在设计时充分考虑了用户体验,通过导航设计和功能分离等方式,确保了系统的易用性和安全性。
该资源为joblib-0.9.0b2-py2.7.egg,欢迎下载使用哦!
一种window下使用mac字体
关于新闻事件的命名实体的测试集数据
内容概要:本文介绍了DARPA的Scalable On-Array Processing(SOAP)项目,旨在通过可扩展算法和分布式架构打破数字阵列瓶颈,提升多波束、多功能RF操作的性能。会议议程包括项目概述、技术挑战、未来扩展计划以及提案提交指南。关键技术挑战包括处理瓶颈和数据传输瓶颈,解决方法涉及分布式处理、迭代算法和光互连等。项目评估标准涵盖科学与技术价值、对DARPA任务的潜在贡献及成本合理性。提案需详细描述如何克服技术难题并满足项目目标。 适合人群:具备雷达系统、信号处理和电子工程背景的研究人员和技术专家,特别是关注国防科技发展的专业人士。 使用场景及目标:①探索大规模数字阵列的高效处理方法;②开发用于干扰抑制、信号增强和其他阵列应用的新算法;③评估分布式硬件架构在实际环境中的表现。 其他说明:提案者应熟悉DARPA的工作流程和合同管理要求,提前准备摘要并积极参与问答环节,确保提案符合项目指南并在规定时间内提交。此外,提案需展示创新性和可行性,并明确阐述技术路径和预期成果。
基于Python的m3u8下载器.zip
bamboo_block
闹钟后盖模具设计及型腔仿真加工.zip
制定三头钻底座(图5-29)的加工工艺,设计钻铰Ф8H7孔的钻床夹具设计.rar
内容概要:本文档提供了基于STM32实现的衣物智能护理机控制应用案例的C++源码框架,整合了温湿度监测、自动除皱、杀菌及烘干功能。硬件配置包括主控芯片STM32F103ZET6、DHT11温湿度传感器、UV-C紫外线杀菌灯、衣物重量压力传感器、继电器控制的PTC加热器、直流风扇、步进电机驱动的机械臂以及ESP8266 WiFi通信模块。控制源码采用HAL库实现,涵盖了外设初始化、PID算法控制烘干、紫外线杀菌控制、机械除皱算法、远程命令处理等功能。文档详细描述了系统的硬件配置、关键外设驱动类实现、多模式控制架构、安全保护机制、扩展接口以及典型工作流程; 适合人群:具有嵌入式系统开发基础,对STM32和C++有一定了解的研发人员; 使用场景及目标:①学习如何使用STM32进行智能设备的控制开发;②掌握温湿度监测、自动除皱、杀菌及烘干功能的具体实现方法;③了解工业级控制逻辑和安全保护机制的设计; 阅读建议:此资源不仅包含代码实现,还涉及硬件配置和系统架构设计,建议读者结合实际硬件进行调试和实践,以加深理解。