Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2325760
  • 博文数量: 535
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7066
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(535)

文章存档

2024年(4)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-05-03 11:57:12

http://hi.baidu.com/cjcht/blog/item/97c7f23e33d069f0838b136b.html



   Maatkit是非常不错的mysql管理工具,网络评价非常不错。包含以下主要工具:

1、mk-table-checksum 检查主从表是否一致的有效工具

2、mk-table-sync 有效保证表一致的工具,不必重载从表而能够保证一致。

3、mk-visual-explain  exlpain解释工具

4、mk-heartbeat 主从同步的监视工具,能够给出从落后于主多少

5、mk-parallel-dump 多线程的mysqldump工具

6、mk-parallel-restore 多线程的表回复工具

7、mk-query-profiler 查询检测分析工具

8、mk-deadlock-logger 死锁的记录工具,支持innodb

9、mk-duplicate-key-checker key侦测工具

10、mk-show-grants 权限管理显示工具

11、mk-slave-restart slave的检测和重启工具

12、mk-slave-delay slave delay replication 的工具

13、mk-slave-prefetch  This tool implements Paul Tuckfield’s famous “oracle” algorithm to read ahead of the slave SQL thread in the relay logs, rewriting queries as SELECT and executing them to warm the slave’s caches. This can help an I/O-bound slave SQL thread run faster under some conditions, because it doesn’t have to wait for as much I/O to complete. 这个看起来非常不错。

Maatkit是非常不错的mysql管理工具,网络评价非常不错。包含以下主要工具:

1、mk-table-checksum 检查主从表是否一致的有效工具

2、mk-table-sync 有效保证表一致的工具,不必重载从表而能够保证一致。

3、mk-visual-explain  exlpain解释工具

4、mk-heartbeat 主从同步的监视工具,能够给出从落后于主多少

5、mk-parallel-dump 多线程的mysqldump工具

6、mk-parallel-restore 多线程的表回复工具

7、mk-query-profiler 查询检测分析工具

8、mk-deadlock-logger 死锁的记录工具,支持innodb








yum -y install dbi* perl*  mysql*





在这里下载这个工具。。

安装如下:
tar zxvf   maatkit-2325.tar.gz
cd maatkit-2325
perl Makefile.PL
make install


mk-table-checksum – 检查数据库复制模式里,master和slave的表是否一致,安装方法可以参考这里。

mysql在5.1之前,其replication都是采用的STATEMENT模式,对表的数据是否一致要求并不严格,所以对数据一致性要求比较严格的应用,定期检查数据一致性是很有必要的,mk-table-checksum 是一个很不错的检查工具。

例如:
我要检查master=192.168.0.1,slave=192.168.0.2的两台mysql的test库里的test表是否一致,命令如下:

? BASH
mk-table-checksum h=192.168.0.1,u=sg,p=sg109504 h=192.168.0.2,u=sg,p=xxxx -d test -t test
DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG
test test 0 192.168.0.1 MyISAM NULL 1592576808 0 0 NULL NULL
test test 0 192.168.0.2 MyISAM NULL 1592576808 0 0 NULL NULL
 
mk-table-checksum h=192.168.0.1,u=sg,p=sg109504 h=192.168.0.2,u=sg,p=xxxx -d test -t test -r
DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG
test test 0 192.168.0.1 MyISAM 385 cd0abd260b2f12c95af05278c114a84b 0 0 NULL NULL
test test 0 192.168.0.2 MyISAM 385 cd0abd260b2f12c95af05278c114a84b 0 0 NULL NULL

解释下输出的意思:
DATABASE:数据库名
TABLE:表名
CHUNK:checksum时的近似数值
HOST:MYSQL的地址
ENGINE:表引擎
COUNT:表的行数
CHECKSUM:校验值
TIME:所用时间
WAIT:等待时间
STAT:MASTER_POS_WAIT()返回值
LAG:slave的延时时间

这里需要顺带介绍下mk-table-checksum的过滤工具mk-checksum-filter,例如我只想知道上面的例子中,test库中哪些表不是一致的。只需要加一个管道符。

? BASH
mk-table-checksum h=10.0.0.156,u=sg,p=sg109504 h=10.0.0.159,u=sg,p=sg109504 -d test -r|mk-checksum-filter
test login_log 0 192.168.0.1 MyISAM 133737 7336e1638a33bbc6a203a41f30b5a6fe 1 0 NULL NULL
test login_log 0 192.168.0.2 MyISAM 133735 609c44faeb584a2c1a92f0a37349a3ea 1 0 NULL NULL

需要提醒一下,在使用mk-table-checksum进行操作的时候,会对表加一个表级锁,所以一般这类检查最好是在业务比较闲的时候进行。下面给

出这2个工具的帮助。

? BASH
mk-table-checksum --help
mk-table-checksum checksums MySQL tables efficiently on one or more HOSTs. Each
HOST is specified as a DSN and missing values are inherited from the first HOST.
If you specify multiple HOSTs, the first is assumed to be the master. For more
details, please use the --help option, or try 'perldoc mk-table-checksum' for
complete documentation.
 
Usage: mk-table-checksum [OPTION]... HOST [HOST...]
 
Options:
--algorithm -a Checksum algorithm (ACCUM|CHECKSUM|BIT_XOR)
--askpass Prompt for a password when connecting to MySQL
--checksum Print checksums and table names in the style of md5sum
(disables --count)
--chunksize -C Approximate number of rows or size of data to checksum at
a time. Allowable suffixes are k, M, G. Disallows -a
CHECKSUM.
--columns Checksum only this comma-separated list of columns
--[no]count -r Count rows in tables. This is built into ACCUM and
BIT_XOR, but requires an extra query for CHECKSUM.
--[no]crc -c Do a CRC (checksum) of tables (default yes)
--databases -d Only checksum this comma-separated list of databases
--defaults-file -F Only read mysql options from the given file. You must give
an absolute pathname.
--emptyrepltbl Empty table given by --replicate before starting
--engine -e Do only this comma-separated list of storage engines
--explain Show, but do not execute, checksum queries (disables
--emptyrepltbl)
--explainhosts Print connection information and exit
--float-precision Precision for FLOAT and DOUBLE column comparisons
--function -f Hash function for checksums (FNV_64, SHA1, MD5, etc)
--help Show this help message
--ignoredb -g Ignore this comma-separated list of databases
--ignoreengine -E Ignore this comma-separated list of storage engines
(default FEDERATED,MRG_MyISAM)
--ignoretbl -n Ignore this comma-separated list of tables
--lock -k Lock on master until done on slaves (implies --slavelag)
--[no]optxor -o Optimize BIT_XOR with user variables (default yes)
--password -p Password to use when connecting
--port -P Port number to use for connection
--quiet -q Do not print checksum results
--replcheck Check results in --replicate table, to the specified depth
--replicate -R Replicate checksums to slaves (disallows -a CHECKSUM)
--separator -s The separator character used for CONCAT_WS() (default #)
--setvars Set these MySQL variables (default wait_timeout=10000)
--slavelag -l Report how far slaves lag master
--sleep Sleep time between checksums
--sleep-coef Calculate --sleep as a multiple of the last checksum time
--socket -S Socket file to use for connection
--tab -b Print tab-separated output, not column-aligned output
--tables -t Do only this comma-separated list of tables
--trim Trim VARCHAR columns (helps when comparing 4.1 to >= 5.0).
--user -u User for login if not current user
--[no]verify -v Verify checksum compatibility across servers (default yes)
--version Output version information and exit
--wait -w Wait this long for slaves to catch up to their master
(implies --lock --slavelag). Optional suffix s=seconds,
m=minutes, h=hours, d=days; if no suffix, s is used.
--where -W Do only rows matching this WHERE clause (disallows
--algorithm CHECKSUM)
 
DSN syntax is key=value[,key=value...] Allowable DSN keys:
KEY COPY MEANING
=== ==== =============================================
A yes Default character set
D yes Database to use
F yes Only read default options from the given file
P yes Port number to use for connection
S yes Socket file to use for connection
h yes Connect to host
p yes Password to use when connecting
u yes User for login if not current user
If the DSN is a bareword, the word is treated as the 'h' key.
 
Options and values after processing arguments:
--algorithm (No value)
--askpass FALSE
--checksum FALSE
--chunksize (No value)
--columns (No value)
--count FALSE
--crc TRUE
--databases (No value)
--defaults-file (No value)
--emptyrepltbl FALSE
--engine (No value)
--explain FALSE
--explainhosts FALSE
--float-precision (No value)
--function (No value)
--help TRUE
--ignoredb
--ignoreengine FEDERATED,MRG_MyISAM
--ignoretbl
--lock FALSE
--optxor TRUE
--password (No value)
--port (No value)
--quiet FALSE
--replcheck (No value)
--replicate (No value)
--separator #
--setvars wait_timeout=10000
--slavelag FALSE
--sleep (No value)
--sleep-coef (No value)
--socket (No value)
--tab FALSE
--tables (No value)
--trim FALSE
--user (No value)
--verify TRUE
--version FALSE
--wait (No value)
--where (No value)
 
mk-checksum-filter --help
mk-checksum-filter filters checksums from mk-table-checksum and prints those
that differ. With no FILE, or when FILE is -, read standard input. For more
details, please use the --help option, or try 'perldoc mk-checksum-filter' for
complete documentation.
 
Usage: mk-checksum-filter FILE
 
Options:
--equaldbs -d This comma-separated list of databases are equal
--header -h Preserves headers output by mk-table-checksum
--help Show this help message
--ignoredb -i Ignore the database name when comparing lines
--master -m The name of the master server
--unique -u Show unique differing host/db/table names
--verbose -v Output all lines, even those that have no differences, except
for header lines
--version Output version information and exit
--ignoredb and --equaldbs are mutually exclusive.
 
Options and values after processing arguments:
--equaldbs
--header FALSE
--help TRUE
--ignoredb FALSE
--master
--unique (No value)
--verbose FALSE
--version FALSE

原文来自:














mk-table-sync?是maatkit里的一个同步主从数据库的利器,执行同步过程中,会同步 DELETE,REPLACE,INSERT,UPDATE语句,mk-table-sync?把包含前面几个的语句都执行一遍,举个例子来说,主从库上 都有:a表,主库上的数据如下:

id      name

1       aa

2       bb

3       cc

4       dd

5       ee

6       ff

从库上的数据如下:

id      name

1       aa

2       bb

3       hh

4       gg

5       ee

那么mk-table-sync会执行3条语句,同步"6 ff"添加到从库,更新"3 cc","4 gg"到从库,一共3条语句,而不是我们看到的从库只比主库少1条数据,其实同步过程中,执行了3条;

执行同步操作一般:

mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t a \
h=localhost,u='root',p='123456' \
h=192.168.0.24,u='root',p='123456'

注意事项:

1.记得加上--charset选项,否则会造成从库乱码;

2.我们如果想要看下到底哪些数据不同步,可以这样做:

mk-table-sync --charset=utf8 --print --no-check-slave -d test -t a \
h='127.0.0.1',u='root',p='123456' \
h
='192.168.0.24',u='root',p='123456'>result

3.如果有好几个从库的话,建议分开同步,除非几个从库的checksum一样;因为每个从库同步的步调不一定都一样,如果几个从库一块同步的话,很容易造成主键冲突,导致主从同步中断,举个例子来说,建议:

mk-table-sync --charset=utf8 --execute --print --no-check-slave -d test -t a \
h='127.0.0.1',u='root',p='123456' \
h
='192.168.0.24',u
='root',p='123456'>result

不建议:

Mysql管理必备工具Maatkit详解之十(mk-parallel-restore)

时间:2010-10-03 15:18来源:chinaunix.net 作者:大头刚 点击:125次
mk-parallel-restore - Load files into MySQL in parallel. 上一篇介绍了mk-parallel-dump并行备份,会把 mysql 的按照database模式,每个表都生成一个单独的备份 文件 ,并统一在你指定的目录。 mk-parallel-restore其实就是mk-parallel-dump的反向操作,也

mk-parallel-restore - Load files into MySQL in parallel.

上一篇介绍了mk-parallel-dump并行备份,会把mysql的按照database模式,每个表都生成一个单独的备份文件,并统一在你指定的目录。
mk-parallel-restore其实就是mk-parallel-dump的反向操作,也会同时启用4个mysql进程去进行恢复,默认优先恢复大表。
使用起来很简单。例如:
mk-parallel-restore -u -p -h /u01/backup/bk_mysql_20090724
如果dump的时候指定了–tab,这里也加上–tab参数
mk-parallel-restore -u -p -h –tab /u01/backup/bk_mysql_20090724
这里需要注意一下,恢复的时候,如果恢复库没有备份库的database需要提前手工创建,mk-parallel-restore不会自动创建。否则会报错
gzip: stdout: Broken pipe
Issuing rollback() for database handle being DESTROY’d without explicit disconnect().
DBD::mysql::db do failed: Unknown database ‘xxxxxx’ at /usr/bin/mk-parallel-restore line 1778.
ok,在看下其他的参数。
mk-parallel-restore --help
mk-parallel-restore loads files into MySQL in parallel.  For more details,
please use the --help option, or try 'perldoc mk-parallel-restore' for complete
documentation.

Usage: mk-parallel-restore options> PATH [PATH...]

Options:
  --askpass             Prompt for a password when connecting to MySQL
  --[no]atomicresume    Treat chunks as atomic when resuming restore (default
                        yes)
  --basedir             Directory where FIFO files will be created
  --[no]biggestfirst    Restore the biggest tables first for highest concurrency
                        (default yes)
  --binlog              Set SQL_LOG_BIN to 1 or 0 to enable or disable binary
                        logging (default 1)
  --bulkinsbufsize      Set bulk_insert_buffer_size before each LOAD DATA INFILE
  --charset         -A  Sets the connection, database, and LOAD DATA INFILE
                        character set (default BINARY)
  --commit              Commit after each load via LOAD DATA INFILE
  --createdb            Create databases if they don't exist
  --csv                 Files are in CSV format (implies --tab)
  --database        -D  Load all files into this database
  --databases       -d  Restore only this comma-separated list of databases
  --dbregex             Restore only databases whose names match this regex
  --decompress          Command used to decompress and print .gz files to STDOUT
                        (like zcat). (default gzip -d -c)
  --defaults-file   -F  Only read mysql options from the given file. You must
                        give an absolute pathname.
  --[no]disablekeys     Execute ALTER TABLE DISABLE KEYS before each table
  --[no]fifo            Stream files into a FIFO for --tab (default yes)
  --help                Show this help message
  --host            -h  Connect to host
  --ignore          -i  Adds the IGNORE modifier to LOAD DATA INFILE
  --ignoredb        -g  Ignore this comma-separated list of databases
  --ignoretbl       -n  Ignore this comma-separated list of table names
  --local           -L  Uses the LOCAL option to LOAD DATA INFILE
  --[no]locktables      Lock tables before LOAD DATA INFILE
  --[no]noautovalon0    Set SQL NO_AUTO_VALUE_ON_ZERO before LOAD DATA INFILE
  --[no]noforeignkeys   Set FOREIGN_KEY_CHECKS=0 before LOAD DATA INFILE
  --noresume            Do not resume restore
  --[no]nouniquechecks  Set UNIQUE_CHECKS=0 before LOAD DATA INFILE
  --numthread       -m  Specifies the number of parallel processes to run
  --password        -p  Password to use when connecting
  --port            -P  Port number to use for connection
  --progress            Display progress messages
  --quiet           -q  Sets --verbose to 0
  --replace         -r  Adds the REPLACE modifier to LOAD DATA INFILE
  --setvars             Set these MySQL variables (default wait_timeout=10000)
  --socket          -S  Socket file to use for connection
  --tab             -T  Load tab-separated files with LOAD DATA INFILE
  --tables          -t  Restore only this comma-separated list of table names
  --tblregex            Restore only tables whose names match this regex
  --test                Print commands instead of executing them
  --truncate            Run TRUNCATE TABLE before LOAD DATA INFILE
  --umask               Set the program's umask to this octal value
  --user            -u  User for login if not current user
  --verbose         -v  Verbosity; can specify multiple times (default 1)
  --version             Output version information and exit
  --wait            -w  Wait limit when server is down (default 5m).  Optional
                        suffix s=seconds, m=minutes, h=hours, d=days; if no
                        suffix, s is used.

Options and values after processing arguments:
  --askpass             FALSE
  --atomicresume        TRUE
  --basedir             /root/cron
  --biggestfirst        TRUE
  --binlog              1
  --bulkinsbufsize      (No value)
  --charset             BINARY
  --commit              FALSE
  --createdb            FALSE
  --csv                 FALSE
  --database            (No value)
  --databases           (No value)
  --dbregex             (No value)
  --decompress          gzip -d -c
  --defaults-file       (No value)
  --disablekeys         FALSE
  --fifo                TRUE
  --help                TRUE
  --host                (No value)
  --ignore              FALSE
  --ignoredb            
  --ignoretbl           
  --local               FALSE
  --locktables          FALSE
  --noautovalon0        FALSE
  --noforeignkeys       FALSE
  --noresume            FALSE
  --nouniquechecks      FALSE
  --numthread           4
  --password            (No value)
  --port                (No value)
  --progress            FALSE
  --quiet               FALSE
  --replace             FALSE
  --setvars             wait_timeout=10000
  --socket              (No value)
  --tab                 FALSE
  --tables              (No value)
  --tblregex            (No value)
  --test                FALSE
  --truncate            FALSE
  --umask               0
  --user                (No value)
  --verbose             1
  --version             FALSE
  --wait                300





Mysql管理必备工具Maatkit详解之五(mk-deadlock-logger)(转)
2010-01-08 09:33

mk-deadlock-logger - 查看mysql的死锁信息。安装方法可以参考。

有2种方式可以查看死锁信息。第一种方法是直接打印出来:

$ mk-deadlock-logger --source u=sg,p=xxxx,h=localhost --print
server ts thread txn_id txn_time user hostname ip db tbl idx lock_type lock_mode wait_hold victim query
localhost 2007-03-08T20:34:22 81 21309 29 baron localhost test c GEN_CLUST_INDEX RECORD X w 1 select * from c for update
localhost 2007-03-08T20:34:22 83 21310 19 baron localhost test a GEN_CLUST_INDEX RECORD X w 0 select * from a for update

OK,很简单的命令,查看最后出现的死锁的信息。当然,你也可以指定想看的信息:

$ mk-deadlock-logger --source u=sg,p=xxxx,h=localhost --print -C ts,user,hostname,db,tbl,idx
ts user hostname db tbl idx
2007-03-08T20:34:22 baron localhost test c GEN_CLUST_INDEX
2007-03-08T20:34:22 baron localhost test a GEN_CLUST_INDEX

第二种方法是把信息储存到指定的表内。首先创建这个表:

mysql> use test;
Database changed
 
mysql> CREATE TABLE deadlocks (
-> server char(20) NOT NULL,
-> ts datetime NOT NULL,
-> thread int unsigned NOT NULL,
-> txn_id bigint unsigned NOT NULL,
-> txn_time smallint unsigned NOT NULL,
-> user char(16) NOT NULL,
-> hostname char(20) NOT NULL,
-> ip char(15) NOT NULL, -- alternatively, ip int unsigned NOT NULL
-> db char(64) NOT NULL,
-> tbl char(64) NOT NULL,
-> idx char(64) NOT NULL,
-> lock_type char(16) NOT NULL,
-> lock_mode char(1) NOT NULL,
-> wait_hold char(1) NOT NULL,
-> victim tinyint unsigned NOT NULL,
-> query text NOT NULL,
-> PRIMARY KEY (server,ts,thread)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.00 sec)
 
mk-deadlock-logger --source u=sg,p=xxxx,h=localhost --dest D=test,\
t=deadlocks --dest D=test,t=deadlocks --daemonize -m 4h -i 30s

OK,这条语句就是,把死锁信息存入deadlocks表,并在4小时内每30秒检查1次。
mysql5.0以后,出现死锁的情况是越来越少了,如果不是innodb引擎。出现死锁的情况,特别的少见。

OK,还有其他的一些参数,可以看下帮助文件。

mk-deadlock-logger --help
mk-deadlock-logger extracts and saves information about the most recent deadlock
in a MySQL server. You need to specify whether to print the output or save it
in a database. For more details, please use the --help option, or try 'perldoc
mk-deadlock-logger' for complete documentation.

Usage: mk-deadlock-logger --source DSN

Options:
--askpass Prompt for a password when connecting to MySQL
--[no]collapse -c Collapse whitespace in queries to a single space
--columns -C Output only this comma-separated list of columns
--daemonize Fork and run in the background; POSIX OSes only
--dest -d DSN for where to store deadlocks
--help Show this help message
--interval -i How often to check for deadlocks (default 0s). Optional
suffix s=seconds, m=minutes, h=hours, d=days; if no suffix,
s is used.
--numip -n Express IP addresses as integers
--print -p Print results on standard output
--setvars Set these MySQL variables (default wait_timeout=10000)
--source -s DSN to check for deadlocks; required
--tab -t Print tab-separated columns, instead of aligned
--time -m How long to run before exiting. Optional suffix s=seconds,
m=minutes, h=hours, d=days; if no suffix, s is used.
--version Output version information and exit
Specify at least one of --print or --dest.
DSN values in --dest default to values from --source.

DSN syntax is key=value[,key=value...] Allowable DSN keys:
KEY COPY MEANING
=== ==== =============================================
A yes Default character set
D yes Database to use
F yes Only read default options from the given file
P yes Port number to use for connection
S yes Socket file to use for connection
h yes Connect to host
p yes Password to use when connecting
t yes Table in which to store deadlock information
u yes User for login if not current user
If the DSN is a bareword, the word is treated as the 'h' key.

Options and values after processing arguments:
--askpass FALSE
--collapse FALSE
--columns (No value)
--daemonize FALSE
--dest (No value)
--help TRUE
--interval 0
--numip FALSE
--print FALSE
--setvars wait_timeout=10000
--source (No value)
--tab FALSE
--time (No value)
--version FALSE

article/y2009/211_mysql%E7%AE%A1%E7%90%86%E5%BF%85%E5%A4%87%E5%B7%A5%E5%85%B7maatkit%E8%AF%A6%E8%A7%A3%E4














Mysql管理工具Maatkit详解之二(mk-archiver)

mk-archiver - 删除时按行备份,支持备份到异地库。安装方法可以参考。

mysql在删除数据的时候,是无法rollback(innodb引擎除外)的,如果你删错了数据,那么你就只能进行恢复了,这显然是很耗成本的操作。
当然你也可以在执行delete的之前,用mysqldump进行备份,或者你在删除之前,先执行load data 或者 insert into as select,至少需要执行2次命令,并且不支持备份到异地库。

那么,下面这个工具可能是你需要的。

利用mk-archiver工具,可以在删除mysql表数据的时候,把需要删除的数据备份。

备份的方式有2种,其一是备份到文件,就像load data一样。其二是备份到另外1张结构相同的表,支持备份到异地库。

mysql> select * from test;
+------+------+
| uid | note |
+------+------+
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
| 4 | NULL |
| 5 | NULL |
| 6 | NULL |
| 7 | NULL |
| 8 | NULL |
| 9 | NULL |
+------+------+
9 rows in set (0.00 sec)

mk-archiver --source h=localhost,u=sg,p='xxxx',D=test,t=test --file '/u01/%Y-%m-%d-%D.%t' --where 'uid<5'
Cannot find an ascendable index in table at /usr/bin/mk-archiver line 1262.

需要给这个表加一个索引。

mysql> create index uid on test(uid);
Current database: test
Query OK, 9 rows affected (0.00 sec)
Records: 9 Duplicates: 0 Warnings: 0

mysql> \! mk-archiver --source h=localhost,u=sg,p='xxxx',D=test,t=test --file '/u01/%Y-%m-%d-%D.%t' --where 'uid<5'

mysql> select * from test;
Current database: test

+------+------+
| uid | note |
+------+------+
| 5 | NULL |
| 6 | NULL |
| 7 | NULL |
| 8 | NULL |
| 9 | NULL |
+------+------+
5 rows in set (0.00 sec)

OK,已经被删除了。被删除的数据在指定的文件里

mysql> \! cat /u01/2008-07-31-test.test
1 \N
2 \N
3 \N
4 \N

想恢复回来,很简单。

mysql> LOAD DATA LOCAL INFILE '/u01/2008-07-31-test.test' into table test;  
Current database: test

Query OK, 4 rows affected (0.01 sec)
Records: 4 Deleted: 0 Skipped: 0 Warnings: 0

mysql> select * from test;
+------+------+
| uid | note |
+------+------+
| 4 | NULL |
| 3 | NULL |
| 2 | NULL |
| 1 | NULL |
| 5 | NULL |
| 6 | NULL |
| 7 | NULL |
| 8 | NULL |
| 9 | NULL |
+------+------+
9 rows in set (0.00 sec)

当然,也可以把数据备份到另外一个相同结构的表,这样需要先把备份表建立,支持备份到异地库。

mysql> create table test2 select * from test where 1=2;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc test2;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| uid | int(11) | YES | | NULL | |
| note | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> select * from test2;
Empty set (0.00 sec)

mysql> \! mk-archiver --source h=localhost,u=sg,p='xxxx',D=test,t=test --dest h=localhost,u=sg,p='xxxx',D=test,t=test2 --where 'uid<5'

mysql> select * from test2;
+------+------+
| uid | note |
+------+------+
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
| 4 | NULL |
+------+------+
4 rows in set (0.00 sec)

OK,还有其他的一些参数,可以看下帮助文件。

mk-archiver --help

mk-archiver nibbles records from a MySQL table. The --source and --dest
arguments use DSN syntax; if COPY is yes, --dest defaults to the key's value
from --source. For more details, please use the --help option, or try 'perldoc
mk-archiver' for complete documentation.

Usage: mk-archiver --source DSN --where WHERE

Options:
--analyze -Z Run ANALYZE TABLE afterwards on --source and/or --dest
--ascendfirst Ascend only first column of index
--askpass Prompt for password for connections
--buffer -b Buffer output to --file and flush at commit
--bulkdel Delete each chunk with a single statement (implies
--commit-each)
--bulkins Insert each chunk with LOAD DATA INFILE (implies --bulkdel
--commit-each)
--charset -A Default character set
--[no]chkcols -C Ensure --source and --dest have same columns (default)
--columns -c Comma-separated list of columns to archive
--commit-each Commit each set of fetched and archived rows (disables -z)
--delayedins Add the DELAYED modifier to INSERT statements
--dest -d Table to archive to
--file -f File to archive to, with DATE_FORMAT()-like formatting
--forupdate Adds the FOR UPDATE modifier to SELECT statements
--header -h Print column header at top of --file
--help Show this help message
--hpselect Adds the HIGH_PRIORITY modifier to SELECT statements
--ignore -i Use IGNORE for INSERT statements
--limit -l Number of rows to fetch and archive per statement (default
1)
--local -L Do not write OPTIMIZE or ANALYZE queries to binlog
--lpdel Add the LOW_PRIORITY modifier to DELETE statements
--lpins Add the LOW_PRIORITY modifier to INSERT statements
--noascend Do not use ascending index optimization
--nodelete Do not delete archived rows
--optimize -O Run OPTIMIZE TABLE afterwards on --source and/or --dest
--pkonly -k Primary key columns only
--plugin Perl module name to use as a generic plugin
--progress -P Print progress information every X rows
--purge -p Purge, not archive; allows to omit --file and --dest
--quickdel Add the QUICK modifier to DELETE statements
--quiet Do not print any output, such as for --statistics
--replace -r Use REPLACE instead of INSERT statements
--retries -R Number of retries per timeout or deadlock (default 1)
--[no]safeautoinc Do not archive row with max AUTO_INCREMENT (default)
--sentinel -S Sentinel file; default /tmp/mk-archiver-sentinel
--setvars Set these MySQL variables (default wait_timeout=10000)
--sharelock Adds LOCK IN SHARE MODE to SELECT statements
--skipfkchk -K Turn off foreign key checks
--sleep -e Sleep time between fetches
--source -s Table to archive from (required)
--statistics Collect and print timing statistics
--stop Stop running instances by creating the sentinel file
--test -t Test: print queries and exit without doing anything
--time -m Time to run before exiting. Optional suffix s=seconds,
m=minutes, h=hours, d=days; if no suffix, s is used.
--txnsize -z Number of rows per transaction; disable with 0; default 1)
--version Output version information and exit
--where -W WHERE clause to limit which rows to archive (required)
--whyquit -q Print reason for exiting unless rows exhausted
--ignore and --replace are mutually exclusive.
--txnsize and --commit-each are mutually exclusive.
--lpins and --delayedins are mutually exclusive.
--sharelock and --forupdate are mutually exclusive.
--analyze and --optimize are mutually exclusive.
Specify at least one of --dest, --file, or --purge.
DSN values in --dest default to values from --source if COPY is yes.




--noascend and --nodelete are mutually exclusive.





阅读(1801) | 评论(0) | 转发(0) |
0

上一篇:SSH无密码访问

下一篇:VMware添加虚拟硬盘

给主人留下些什么吧!~~