1MAATKIT(1) User Contributed Perl Documentation MAATKIT(1)
2
3
4
6 maatkit - Essential command-line utilities for MySQL.
7
9 Maatkit is a collection of command-line utilities that provide missing
10 functionality for MySQL. Some of the tools implement lacking server
11 functionality, such as online consistency checks for master/slave
12 replication; others are client-side utilities such as a query profiler.
13
14 The following tools are included:
15
16 $Revision: 6839 $
17 mk-archiver 1.0.23
18 mk-deadlock-logger 1.0.21
19 mk-duplicate-key-checker 1.2.13
20 mk-error-log 1.0.3
21 mk-fifo-split 1.0.7
22 mk-find 0.9.23
23 mk-heartbeat 1.0.22
24 mk-index-usage 0.9.0
25 mk-kill 0.9.6
26 mk-loadavg 0.9.6
27 mk-log-player 1.0.8
28 mk-parallel-dump 1.0.26
29 mk-parallel-restore 1.0.23
30 mk-purge-logs 0.9.0
31 mk-query-advisor 1.0.0
32 mk-query-digest 0.9.20
33 mk-query-profiler 1.1.22
34 mk-show-grants 1.0.23
35 mk-slave-delay 1.0.22
36 mk-slave-find 1.0.13
37 mk-slave-move 0.9.12
38 mk-slave-prefetch 1.0.20
39 mk-slave-restart 1.0.22
40 mk-table-checksum 1.2.17
41 mk-table-sync 1.0.30
42 mk-upgrade 0.9.8
43 mk-variable-advisor 1.0.0
44 mk-visual-explain 1.0.22
45
46 mk-archiver
47 Archive rows from a MySQL table into another table or a file. See
48 mk-archiver.
49
50 mk-checksum-filter
51 Filter checksums from mk-table-checksum. See mk-checksum-filter.
52
53 mk-deadlock-logger
54 Extract and log MySQL deadlock information. See mk-deadlock-logger.
55
56 mk-duplicate-key-checker
57 Find duplicate indexes and foreign keys on MySQL tables. See mk-
58 duplicate-key-checker.
59
60 mk-error-log
61 Find new and different MySQL error log entries. See mk-error-log.
62
63 mk-fifo-split
64 Split files and pipe lines to a fifo without really splitting. See
65 mk-fifo-split.
66
67 mk-find
68 Find MySQL tables and execute actions, like GNU find. See mk-find.
69
70 mk-heartbeat
71 Monitor MySQL replication delay. See mk-heartbeat.
72
73 mk-index-usage
74 Read queries from a log and analyze how they use indexes. See mk-
75 index-usage.
76
77 mk-kill
78 Kill MySQL queries that match certain criteria. See mk-kill.
79
80 mk-loadavg
81 Watch MySQL load and take action when it gets too high. See mk-
82 loadavg.
83
84 mk-log-player
85 Split and play MySQL slow logs. See mk-log-player.
86
87 mk-merge-mqd-results
88 Merge multiple mk-query-digest reports into one. See mk-merge-mqd-
89 results.
90
91 mk-parallel-dump
92 Dump MySQL tables in parallel. See mk-parallel-dump.
93
94 mk-parallel-restore
95 Load files into MySQL in parallel. See mk-parallel-restore.
96
97 mk-profile-compact
98 Compact the output from mk-query-profiler. See mk-profile-compact.
99
100 mk-purge-logs
101 Purge binary logs on a master based on purge rules. See mk-purge-
102 logs.
103
104 mk-query-advisor
105 Analyze queries and advise on possible problems. See mk-query-
106 advisor.
107
108 mk-query-digest
109 Parses logs and more. Analyze, transform, filter, review and
110 report on queries. See mk-query-digest.
111
112 mk-query-profiler
113 Execute SQL statements and print statistics, or measure activity
114 caused by other processes. See mk-query-profiler.
115
116 mk-show-grants
117 Canonicalize and print MySQL grants so you can effectively
118 replicate, compare and version-control them. See mk-show-grants.
119
120 mk-slave-delay
121 Make a MySQL slave server lag behind its master. See mk-slave-
122 delay.
123
124 mk-slave-find
125 Find and print replication hierarchy tree of MySQL slaves. See mk-
126 slave-find.
127
128 mk-slave-move
129 Move a MySQL slave around in the replication hierarchy. See mk-
130 slave-move.
131
132 mk-slave-prefetch
133 Pipeline relay logs on a MySQL slave to pre-warm caches. See mk-
134 slave-prefetch.
135
136 mk-slave-restart
137 Watch and restart MySQL replication after errors. See mk-slave-
138 restart.
139
140 mk-table-checksum
141 Perform an online replication consistency check, or checksum MySQL
142 tables efficiently on one or many servers. See mk-table-checksum.
143
144 mk-table-sync
145 Synchronize MySQL tables efficiently. See mk-table-sync.
146
147 mk-upgrade
148 Execute queries on multiple servers and check for differences. See
149 mk-upgrade.
150
151 mk-variable-advisor
152 Analyze MySQL variables and advise on possible problems. See mk-
153 variable-advisor.
154
155 mk-visual-explain
156 Format EXPLAIN output as a tree. See mk-visual-explain.
157
159 Strictly speaking these tools require no installation; you should be
160 able to run them stand-alone. However, on UNIX-ish systems you can use
161 the standard Perl installation sequence:
162
163 cd <package directory>
164 perl Makefile.PL
165 make install
166
168 Maatkit tools can read options from configuration files. The
169 configuration file syntax is simple and direct, and bears some
170 resemblances to the MySQL command-line client tools. The configuration
171 files all follow the same conventions.
172
173 Internally, what actually happens is that the lines are read from the
174 file and then added as command-line options and arguments to the
175 Maatkit tool, so just think of the configuration files as a way to
176 write your command lines.
177
178 SYNTAX
179 The syntax of the files is as follows:
180
181 · Whitespace followed by a hash (#) sign signifies that the rest of
182 the line is a comment. This is deleted.
183
184 · Whitespace is stripped from the beginning and end of all lines.
185
186 · Empty lines are ignored.
187
188 · Each line is permitted to be in either of the following formats:
189
190 option
191 option=value
192
193 Whitespace around the equals sign is deleted during processing.
194
195 · Only long options are recognized.
196
197 · A line containing only two hyphens signals the end of option
198 parsing. Any further lines are interpreted as additional arguments
199 (not options) to the program.
200
201 FILES
202 The tools read several configuration files in order:
203
204 1. The global Maatkit configuration file, /etc/maatkit/maatkit.conf.
205 All tools read this file, so you should only add options to it that
206 you want to apply to all Maatkit tools.
207
208 2. The global tool configuration file, /etc/maatkit/[toolname].conf.
209 This file is named after the specific tool you're using, so you can
210 add options that apply only to that tool.
211
212 3. The user's own Maatkit configuration file, $HOME/.maatkit.conf.
213 All tools read this file, so you should only add options to it that
214 you want to apply to all Maatkit tools.
215
216 4. The user's tool configuration file, $HOME/.[toolname].conf. This
217 file is named after the specific tool you're using, so you can add
218 options that apply only to that tool.
219
220 SPECIFYING CONFIGURATION FILES
221 There is a special --config option, which lets you specify which
222 configuration files Maatkit should read. You specify a comma-separated
223 list of files. However, its behavior is not like other command-line
224 options. It must be given first on the command line, before any other
225 options. If you try to specify it anywhere else, it will cause an
226 error. Also, you cannot specify --config=/path/to/file; you must
227 specify the option and the path to the file(s) separated by whitespace,
228 without an equals-sign between them, e.g.
229
230 --config /path/to/file
231
232 If you don't want any configuration files at all, specify "--config ''"
233 to provide an empty list of files.
234
236 Maatkit uses DSNs to specify how to create a DBD connection to a MySQL
237 server. The maatkit tools that have command-line arguments such as -u
238 or -p use them to create a DSN behind the scenes, then use the DSN to
239 connect to MySQL.
240
241 A DSN is a string of key=value parts separated by commas. The possible
242 keys are shown later in this document. You can also get a quick
243 synopsis from the --help output of many of the maatkit tools.
244
245 PARTS
246 Many of the tools add more parts to DSNs for special purposes, and
247 sometimes override parts to make them do something slightly different.
248 However, all the tools support at least the following:
249
250 A Specifies the default character set for the connection.
251
252 Enables character set settings in Perl and MySQL. If the value is
253 "utf8", sets Perl's binmode on STDOUT to utf8, passes the
254 "mysql_enable_utf8" option to DBD::mysql, and runs "SET NAMES UTF8"
255 after connecting to MySQL. Any other value sets binmode on STDOUT
256 without the utf8 layer, and runs "SET NAMES" after connecting to
257 MySQL.
258
259 Unfortunately, there is no way from within Perl itself to specify
260 the client library's character set. "SET NAMES" only affects the
261 server; if the client library's settings don't match, there could
262 be problems. You can use the defaults file to specify the client
263 library's character set, however. See the description of the F
264 part below.
265
266 D Specifies the connection's default database.
267
268 F Specifies a defaults file the mysql client library (the C client
269 library used by DBD::mysql, not maatkit itself) should read. The
270 maatkit tools all read the [client] section within the defaults
271 file. If you omit this, the standard defaults files will be read
272 in the usual order. "Standard" varies from system to system,
273 because the filenames to read are compiled into the client library.
274 On Debian systems, for example, it's usually /etc/mysql/my.cnf then
275 ~/.my.cnf. If you place the following into ~/.my.cnf, maatkit will
276 Do The Right Thing:
277
278 [client]
279 user=your_user_name
280 pass=secret
281
282 Omitting the F part is usually the right thing to do. As long as
283 you have configured your ~/.my.cnf correctly, that will result in
284 maatkit connecting automatically without needing a username or
285 password.
286
287 You can also specify a default character set in the defaults file.
288 Unlike the "A" part described above, this will actually instruct
289 the client library (DBD::mysql) to change the character set it uses
290 internally, which cannot be accomplished any other way as far as I
291 know, except for "utf8".
292
293 P Port number to use for the connection. Note that the usual
294 special-case behaviors apply: if you specify "localhost" as your
295 hostname on Unix systems, the connection actually uses a socket
296 file, not a TCP/IP connection, and thus ignores the port.
297
298 S Socket file to use for the connection (on Unix systems).
299
300 h Hostname or IP address for the connection.
301
302 p Password to use when connecting.
303
304 u User for login if not current user.
305
306 BAREWORD
307 Many of the tools will let you specify a DSN as a single word, without
308 any key=value syntax. This is called a 'bareword'. How this is
309 handled is tool-specific, but it is usually interpreted as the "h"
310 part. The tool's --help output will tell you the behavior for that
311 tool.
312
313 DEFAULT PROPAGATION
314 Many tools will let you propagate values from one DSN to the next, so
315 you don't have to specify all the parts for each DSN. For example, if
316 you want to specify a username and password for each DSN, you can
317 connect to three hosts as follows:
318
319 h=host1,u=fred,p=wilma host2 host3
320
321 This is tool-specific.
322
324 You need Perl, DBI, DBD::mysql, and some core packages that ought to be
325 installed in any reasonably new version of Perl.
326
328 If you find bugs, need features, etc please use the bug tracker,
329 forums, and mailing lists at http://code.google.com/p/maatkit/
330
332 This program is copyright (c) 2007 Baron Schwartz and others. Feedback
333 and improvements are welcome.
334
335 THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
336 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
337 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
338
339 This program is free software; you can redistribute it and/or modify it
340 under the terms of the GNU General Public License as published by the
341 Free Software Foundation, version 2; OR the Perl Artistic License. On
342 UNIX and similar systems, you can issue `man perlgpl' or `man
343 perlartistic' to read these licenses.
344
345 You should have received a copy of the GNU General Public License along
346 with this program; if not, write to the Free Software Foundation, Inc.,
347 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
348
350 See the individual program's documentation for details.
351
353 This manual page documents Distrib 6839 $Revision: 534 $.
354
355
356
357perl v5.12.1 2010-08-01 MAATKIT(1)