.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. | will give a .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' .\" expand to `' in nroff, nothing in troff, for use with C<>. .tr \(*W-|\(bv\*(Tr .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MYSQL-FIND 1" .TH MYSQL-FIND 1 "2007-10-15" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" mysql\-find \- Find MySQL tables and execute actions, like GNU find. .SH "DESCRIPTION" .IX Header "DESCRIPTION" mysql-find looks for MySQL tables that pass the tests you specify, and executes the actions you specify. The default action is to print the database and table name to \s-1STDOUT\s0. .PP mysql-find is simpler than \s-1GNU\s0 find. It doesn't allow you to specify complicated expressions on the command line. .PP mysql-find only looks for and processes tables. If you need it to do other things, like triggers or columns, file a bug report and I'll add the features. .PP mysql-find uses \s-1SHOW\s0 \s-1TABLES\s0 when possible, and \s-1SHOW\s0 \s-1TABLE\s0 \s-1STATUS\s0 when needed. .SH "OPTIONS" .IX Header "OPTIONS" There are three kinds of options: normal options, which determine some behavior or setting; tests, which determine whether a table should be included in the list of tables found; and actions, which do something to the tables mysql-find finds. .PP mysql-find uses standard Getopt::Long option parsing, so you should use double dashes in front of long option names, unlike \s-1GNU\s0 find. .Sh "\s-1OPTIONS\s0" .IX Subsection "OPTIONS" .IP "\-\-askpass" 4 .IX Item "--askpass" Prompt for password for connections. .IP "\-\-case\-insensitive" 4 .IX Item "--case-insensitive" Specifies that all regular expression searches are case\-insensitive. .IP "\-\-daystart" 4 .IX Item "--daystart" Measure times (for \*(L"\-\-mmin\*(R", etc) from the beginning of today rather than from the current time. .IP "\-\-defaults\-file" 4 .IX Item "--defaults-file" If you specify this option, only this file is read for MySQL default options; otherwise all the default files will be read. .IP "\-\-help" 4 .IX Item "--help" Displays a help message. .IP "\-\-host" 4 .IX Item "--host" Connect to host. .IP "\-\-or" 4 .IX Item "--or" By default, tests are evaluated as though there were an \s-1AND\s0 between them. This option switches it to \s-1OR\s0. .Sp Option parsing is not implemented by mysql-find itself, so you cannot specify complicated expressions with parentheses and mixtures of \s-1OR\s0 and \s-1AND\s0. .IP "\-\-password" 4 .IX Item "--password" The password to use when connecting. .IP "\-\-port" 4 .IX Item "--port" The port number to use for the connection. .IP "\-\-quote" 4 .IX Item "--quote" This option is enabled by default. It quotes MySQL identifier names with MySQL's standard backtick character. Quoting happens after tests are run, and before actions are run. .IP "\-\-socket" 4 .IX Item "--socket" The socket file to use for the connection. .IP "\-\-user" 4 .IX Item "--user" The user for login if not the current user. .IP "\-\-version" 4 .IX Item "--version" Output version information and exit. .Sh "\s-1TESTS\s0" .IX Subsection "TESTS" Most tests check some criterion against a column of \s-1SHOW\s0 \s-1TABLE\s0 \s-1STATUS\s0 output. Numeric arguments can be specified as +n for greater than n, \-n for less than n, and n for exactly n. All numeric options can take an optional suffix multiplier of k, M or G (1_024, 1_048_576, and 1_073_741_824 respectively). All patterns are Perl regular expressions (see 'man perlre') unless specified as \s-1SQL\s0 \s-1LIKE\s0 patterns. .PP Dates and times are all measured relative to the same instant, when mysql-find first asks the database server what time it is. All date and time manipulation is done in \s-1SQL\s0, so if you say to find tables modified 5 days ago, that translates to \s-1SELECT\s0 \s-1DATE_SUB\s0(\s-1CURRENT_TIMESTAMP\s0, \s-1INTERVAL\s0 5 \s-1DAY\s0). If you specify \*(L"\-\-daystart\*(R", if course it's relative to \s-1CURRENT_DATE\s0 instead. .PP However, table sizes and other metrics are not consistent at an instant in time. It can take some time for MySQL to process all the \s-1SHOW\s0 queries, and mysql-find can't do anything about that. These measurements are as of the time they're taken. .PP If you need some test that's not in this list, file a bug report and I'll enhance mysql-find for you. It's really easy. .IP "\-\-autoinc" 4 .IX Item "--autoinc" Table's next \s-1AUTO_INCREMENT\s0 is n. This tests the Auto_increment column. .IP "\-\-avgrowlen" 4 .IX Item "--avgrowlen" Table avg row len is n bytes. This tests the Avg_row_length column. .IP "\-\-checksum" 4 .IX Item "--checksum" Table checksum is n. This tests the Checksum column. .IP "\-\-cmin" 4 .IX Item "--cmin" Table was created n minutes ago. This tests the Create_time column. .IP "\-\-collation" 4 .IX Item "--collation" Table collation matches pattern. This tests the Collation column. .IP "\-\-comment" 4 .IX Item "--comment" Table comment matches pattern. This tests the Comment column. .IP "\-\-createopts" 4 .IX Item "--createopts" Table create option matches pattern. This tests the Create_options column. .IP "\-\-ctime" 4 .IX Item "--ctime" Table was created n days ago. This tests the Create_time column. .IP "\-\-datasize" 4 .IX Item "--datasize" Table data uses n bytes of space. This tests the Data_length column. .IP "\-\-datafree" 4 .IX Item "--datafree" Table has n bytes of free space. This tests the Data_free column. .IP "\-\-dblike" 4 .IX Item "--dblike" Database name matches \s-1SQL\s0 \s-1LIKE\s0 pattern. .IP "\-\-dbregex" 4 .IX Item "--dbregex" Database name matches this pattern. .IP "\-\-empty" 4 .IX Item "--empty" Table has no rows. This tests the Rows column. .IP "\-\-engine" 4 .IX Item "--engine" Table storage engine matches this pattern. This tests the Engine column, or in earlier versions of MySQL, the Type column. .IP "\-\-indexsize" 4 .IX Item "--indexsize" Table indexes use n bytes of space. This tests the Index_length column. .IP "\-\-kmin" 4 .IX Item "--kmin" Table was checked n minutes ago. This tests the Check_time column. .IP "\-\-ktime" 4 .IX Item "--ktime" Table was checked n days ago. This tests the Check_time column. .IP "\-\-mmin" 4 .IX Item "--mmin" Table was last modified n minutes ago. This tests the Update_time column. .IP "\-\-mtime" 4 .IX Item "--mtime" Table was last modified n days ago. This tests the Update_time column. .IP "\-\-pid" 4 .IX Item "--pid" Table name has nonexistent MySQL connection \s-1ID\s0. This tests the table name for a pattern. The argument to this test must be a Perl regular expression that captures digits like this: (\ed+). If the table name matches the pattern, these captured digits are taken to be the MySQL connection \s-1ID\s0 of some process. If the connection doesn't exist according to \s-1SHOW\s0 \s-1FULL\s0 \s-1PROCESSLIST\s0, the test returns true. If the connection \s-1ID\s0 is greater than mysql\-find's own connection \s-1ID\s0, the test returns false for safety. .Sp Why would you want to do this? If you use MySQL statement-based replication, you probably know the trouble temporary tables can cause. You might choose to work around this by creating real tables with unique names, instead of temporary tables. One way to do this is to append your connection \s-1ID\s0 to the end of the table, thusly: scratch_table_12345. This assures the table name is unique and lets you have a way to find which connection it was associated with. And perhaps most importantly, if the connection no longer exists, you can assume the connection died without cleaning up its tables, and this table is a candidate for removal. .Sp This how I manage scratch tables, and that's why I included this test in mysql\-find. .Sp The argument I use to \*(L"\-\-pid\*(R" is \*(L"\eD_(\ed+)$\*(R". That finds tables with a series of numbers at the end, preceded by an underscore and some non-number character (the latter criterion prevents me from examining tables with a date at the end, which people tend to do: baron_scratch_2007_05_07 for example). It's better to keep the scratch tables separate of course. .Sp If you do this, make sure the user mysql-find runs as has the \s-1PROCESS\s0 privilege! Otherwise it will only see connections from the same user, and might think some tables are ready to remove when they're still in use. For safety, mysql-find checks this for you. .IP "\-\-rows" 4 .IX Item "--rows" Table has n rows. This tests the Rows column. .IP "\-\-rowformat" 4 .IX Item "--rowformat" Table row format matches pattern. This tests the Row_format column. .IP "\-\-tablesize" 4 .IX Item "--tablesize" Table uses n bytes of space. This tests the sum of the Data_length and Index_length columns. .IP "\-\-tbllike" 4 .IX Item "--tbllike" Table name matches \s-1SQL\s0 \s-1LIKE\s0 pattern. .IP "\-\-tblregex" 4 .IX Item "--tblregex" Table name matches this pattern. .IP "\-\-tblversion" 4 .IX Item "--tblversion" Table version is n. This tests the Version column. .Sh "\s-1ACTIONS\s0" .IX Subsection "ACTIONS" The exec_plus action happens after everything else, but otherwise actions happen in an indeterminate order. If you need determinism, file a bug report and I'll add this feature. .IP "\-\-exec" 4 .IX Item "--exec" Execute this \s-1SQL\s0 with each item found. The \s-1SQL\s0 can contain escapes and formatting directives (see \*(L"\-\-printf\*(R"). .IP "\-\-exec_plus" 4 .IX Item "--exec_plus" Execute this \s-1SQL\s0 with all items at once. This option is unlike \*(L"\-\-exec\*(R". There are no escaping or formatting directives; there is only one special placeholder for the list of database and table names, \f(CW%s\fR. The list of tables found will be joined together with commas and substituted wherever you place \f(CW%s\fR. .Sp You might use this, for example, to drop all the tables you found: .Sp .Vb 1 \& DROP TABLE %s .Ve .Sp This is sort of like \s-1GNU\s0 find's \*(L"\-exec command {} +\*(R" syntax. Only it's not totally cryptic. And it doesn't require me to write a command-line parser. .IP "\-\-print" 4 .IX Item "--print" Print the database and table name, followed by a newline. This is the default action if no other action is specified. .IP "\-\-printf" 4 .IX Item "--printf" Print format on the standard output, interpreting '\e' escapes and '%' directives. Escapes are backslashed characters, like \en and \et. Perl interprets these, so you can use any escapes Perl knows about. Directives are replaced by \f(CW%s\fR, and as of this writing, you can't add any special formatting instructions, like field widths or alignment (though I'm musing over ways to do that). .Sp Here is a list of the directives. Note that most of them simply come from columns of \s-1SHOW\s0 \s-1TABLE\s0 \s-1STATUS\s0. If the column is \s-1NULL\s0 or doesn't exist, you get an empty string in the output. A % character followed by any character not in the following list is discarded (but the other character is printed). .Sp .Vb 23 \& CHAR DATA SOURCE NOTES \& ---- ------------------ ------------------------------------------ \& a Auto_increment \& A Avg_row_length \& c Checksum \& C Create_time \& D Database The database name in which the table lives \& d Data_length \& E Engine In older versions of MySQL, this is Type \& F Data_free \& f Innodb_free Parsed from the Comment field \& I Index_length \& K Check_time \& L Collation \& M Max_data_length \& N Name \& O Comment \& P Create_options \& R Row_format \& S Rows \& T Table_length Data_length+Index_length \& U Update_time \& V Version .Ve .SH "EXAMPLES" .IX Header "EXAMPLES" Find all tables created more than a day ago, which use the MyISAM engine, and print their names: .PP .Vb 1 \& mysql-find --ctime +1 --engine MyISAM .Ve .PP Find InnoDB tables that haven't been updated in a month, and convert them to MyISAM storage engine (data warehousing, anyone?): .PP .Vb 1 \& mysql-find --mtime +30 --engine InnoDB --exec "ALTER TABLE %D.%N ENGINE=MyISAM" .Ve .PP Find tables created by a process that no longer exists, following the name_pid naming convention, and remove them. .PP .Vb 1 \& mysql-find --pid '\eD_(\ed+)$' --exec_plus "DROP TABLE %s" .Ve .PP Find empty tables in the test and junk databases, and delete them: .PP .Vb 1 \& mysql-find --empty junk test --exec_plus "DROP TABLE %s" .Ve .PP Find tables more than five gigabytes in total size: .PP .Vb 1 \& mysql-find --tablesize +5G .Ve .PP Find all tables and print their total data and index size, and sort largest tables first (sort is a different program, by the way). .PP .Vb 1 \& mysql-find --printf "%T\et%D.%N\en" | sort -rn .Ve .PP As above, but this time, insert the data back into the database for posterity: .PP .Vb 1 \& mysql-find --noquote --exec "INSERT INTO sysdata.tblsize(db, tbl, size) VALUES('%D', '%N', %T)" .Ve .SH "BUGS" .IX Header "BUGS" Please use the Sourceforge bug tracker, forums, and mailing lists to request support or report bugs: . .SH "SYSTEM REQUIREMENTS" .IX Header "SYSTEM REQUIREMENTS" You need the following Perl modules: \s-1DBI\s0 and DBD::mysql. .SH "LICENSE" .IX Header "LICENSE" This program is copyright (c) 2007 Baron Schwartz. Feedback and improvements are welcome (see \*(L"\s-1BUGS\s0\*(R"). .PP \&\s-1THIS\s0 \s-1PROGRAM\s0 \s-1IS\s0 \s-1PROVIDED\s0 \*(L"\s-1AS\s0 \s-1IS\s0\*(R" \s-1AND\s0 \s-1WITHOUT\s0 \s-1ANY\s0 \s-1EXPRESS\s0 \s-1OR\s0 \s-1IMPLIED\s0 \&\s-1WARRANTIES\s0, \s-1INCLUDING\s0, \s-1WITHOUT\s0 \s-1LIMITATION\s0, \s-1THE\s0 \s-1IMPLIED\s0 \s-1WARRANTIES\s0 \s-1OF\s0 \&\s-1MERCHANTIBILITY\s0 \s-1AND\s0 \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. .PP This program is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation, version 2; \s-1OR\s0 the Perl Artistic License. On \s-1UNIX\s0 and similar systems, you can issue `man perlgpl' or `man perlartistic' to read these licenses. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, \s-1MA\s0 02111\-1307 \s-1USA\s0. .SH "AUTHOR" .IX Header "AUTHOR" Baron Schwartz. .SH "VERSION" .IX Header "VERSION" This manual page documents Ver 0.9.5 Distrib 1053 \f(CW$Revision:\fR 940 $.