PERCONA-TOOLKIT(1p) | User Contributed Perl Documentation | PERCONA-TOOLKIT(1p) |
percona-toolkit - Advanced command-line tools for MySQL
Percona Toolkit is a collection of advanced command-line tools used by Percona (<http://www.percona.com/>) support staff to perform a variety of MySQL and system tasks that are too difficult or complex to perform manually.
These tools are ideal alternatives to private or "one-off" scripts because they are professionally developed, formally tested, and fully documented. They are also fully self-contained, so installation is quick and easy and no libraries are installed.
Percona Toolkit is derived from Maatkit and Aspersa, two of the best-known toolkits for MySQL server administration. It is developed and supported by Percona. For more information and other free, open-source software developed by Percona, visit <http://www.percona.com/software/>.
This release of Percona Toolkit includes the following tools:
For more free, open-source software developed Percona, visit <http://www.percona.com/software/>.
Tool options use standard types ("int", "string", etc.) as well as these special types:
Percona Toolkit tools can read options from configuration files. The configuration file syntax is simple and direct, and bears some resemblances to the MySQL command-line client tools. The configuration files all follow the same conventions.
Internally, what actually happens is that the lines are read from the file and then added as command-line options and arguments to the tool, so just think of the configuration files as a way to write your command lines.
The syntax of the configuration files is as follows:
option option=value
Do not prefix the option with "--". Do not quote the values, even if it has spaces; value are literal. Whitespace around the equals sign is deleted during processing.
This config file for pt-stalk,
# Config for pt-stalk variable=Threads_connected cycles=2 # trigger if problem seen twice in a row -- --user daniel
is equivalent to this command line:
pt-stalk --variable Threads_connected --cycles 2 -- --user daniel
Options after "--" are passed literally to mysql and mysqladmin.
The tools read several configuration files in order:
There is a special "--config" option, which lets you specify which configuration files Percona Toolkit should read. You specify a comma-separated list of files. However, its behavior is not like other command-line options. It must be given first on the command line, before any other options. If you try to specify it anywhere else, it will cause an error. Also, you cannot specify "--config=/path/to/file"; you must specify the option and the path to the file separated by whitespace without an equal sign between them, like:
--config /path/to/file
If you don't want any configuration files at all, specify "--config ''" to provide an empty list of files.
Percona Toolkit tools use DSNs to specify how to create a DBD connection to a MySQL server. A DSN is a comma-separated string of "key=value" parts, like:
h=host1,P=3306,u=bob
The standard key parts are shown below, but some tools add additional key parts. See each tool's documentation for details.
Some tools do not use DSNs but still connect to MySQL using options like "--host", "--user", and "--password". Such tools uses these options to create a DSN automatically, behind the scenes.
Other tools uses both DSNs and options like the ones above. The options provide defaults for all DSNs that do not specify the option's corresponding key part. For example, if DSN "h=host1" and option "--port=12345" are specified, then the tool automatically adds "P=12345" to DSN.
DSNs are usually specified on the command line, so shell quoting and escaping must be taken into account. Special characters, like asterisk ("*"), need to be quoted and/or escaped properly to be passed as literal characters in DSN values.
Since DSN parts are separated by commas, literal commas in DSN values must be escaped with a single backslash ("\"). And since a backslash is the escape character for most shells, two backslashes are required to pass a literal backslash. For example, if the username is literally "my,name", it must be specified as "my\\,name" on most shells. This applies to DSNs and DSN-related options like "--user".
Many of the tools add more parts to DSNs for special purposes, and sometimes override parts to make them do something slightly different. However, all the tools support at least the following:
Enables character set settings in Perl and MySQL. 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. Other values set binmode on STDOUT without the utf8 layer and run "SET NAMES" after connecting to MySQL.
Unfortunately, there is no way from within Perl itself to specify the client library's character set. "SET NAMES" only affects the server; if the client library's settings don't match, there could be problems. You can use the defaults file to specify the client library's character set, however. See the description of the F part below.
[client] user=your_user_name pass=secret
Omitting the F part is usually the right thing to do. As long as you have configured your "~/.my.cnf" correctly, that will result in tools connecting automatically without needing a username or password.
You can also specify a default character set in the defaults file. Unlike the "A" part described above, this will actually instruct the client library (DBD::mysql) to change the character set it uses internally, which cannot be accomplished any other way.
For some reason, some vendors compile libmysql without the --enable-local-infile option, which disables the statement. This can lead to weird situations, like the server allowing LOCAL INFILE, but the client throwing exceptions if it's used.
However, as long as the server allows LOAD DATA, clients can easily re-enable it; see <https://dev.mysql.com/doc/refman/5.0/en/load-data-local.html> and <http://search.cpan.org/~capttofu/DBD-mysql/lib/DBD/mysql.pm>. This option does exactly that.
Many of the tools will let you specify a DSN as a single word, without any "key=value" syntax. This is called a 'bareword'. How this is handled is tool-specific, but it is usually interpreted as the "h" part. The tool's "--help" output will tell you the behavior for that tool.
Many tools will let you propagate values from one DSN to the next, so you don't have to specify all the parts for each DSN. For example, if you want to specify a username and password for each DSN, you can connect to three hosts as follows:
h=host1,u=fred,p=wilma host2 host3
This is tool-specific.
The environment variable "PTDEBUG" enables verbose debugging output to STDERR. To enable debugging and capture all output to a file, run the tool like:
PTDEBUG=1 pt-table-checksum ... > FILE 2>&1
Be careful: debugging output is voluminous and can generate several megabytes of output.
Most tools require:
Tools that connect to MySQL require:
Percona Toolkit officially supports and is tested on many popular Linux distributions and MySQL 5.0 through 5.6; see http://goo.gl/srHm7 for the list of supported platforms and versions.
Please report bugs at <https://jira.percona.com>. Include the following information in your bug report:
If possible, include debugging output by running the tool with "PTDEBUG"; see "ENVIRONMENT".
Percona Toolkit is copyright 2011-2018 Percona LLC and/or its affiliates, et al. See each program's documentation for complete copyright notices.
THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.
Percona Toolkit v3.0.13 released 2018-12-28
2019-02-03 | perl v5.28.1 |