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:
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.
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:
Specifies the default character set for the connection.
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. Any other value sets binmode on STDOUT without the utf8 layer, and runs 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.
Specifies the connection’s default database.
Specifies a defaults file the mysql client library (the C client library used by DBD::mysql, not Percona Toolkit itself) should read. The tools all read the [client] section within the defaults file. If you omit this, the standard defaults files will be read in the usual order. “Standard” varies from system to system, because the filenames to read are compiled into the client library. On Debian systems, for example, it’s usually /etc/mysql/my.cnf then ~/.my.cnf. If you place the following into ~/.my.cnf, tools will Do The Right Thing:[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 as far as I know, except for utf8.
Hostname or IP address for the connection.
Password to use when connecting.
Port number to use for the connection. Note that the usual special-case behaviors apply: if you specify localhost as your hostname on Unix systems, the connection actually uses a socket file, not a TCP/IP connection, and thus ignores the port.
Socket file to use for the connection (on Unix systems).
User for login if not current user.
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.
For general inquiries, please send us your question and someone will contact you.