DSN (DATA SOURCE NAME) SPECIFICATIONS

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.

KEY PARTS

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:

A

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.

D

Specifies the connection’s default database.

F

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.

h

Hostname or IP address for the connection.

p

Password to use when connecting.

P

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.

S

Socket file to use for the connection (on Unix systems).

u

User for login if not current user.

BAREWORD

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.

PROPAGATION

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.

Percona Toolkit
Call Us
+1-888-316-9775 (USA - Sales)
+1-208-473-2904 (USA - Sales)
+44-208-133-0309 (UK - Sales)
0-800-051-8984 (UK - Sales)
0-800-181-0665 (GER - Sales)
+1-877-862-4316 (Emergency)
+1-855-55TRAIN (Training)
+1-925-271-5054 (Training)

Table Of Contents

Previous topic

CONFIGURATION FILES

Next topic

ENVIRONMENT

This Page



© Copyright 2011, Percona Inc.
Except where otherwise noted, this documentation is licensed under the following license:
CC Attribution-ShareAlike 2.0 Generic
Created using Sphinx 1.1.3.
This documentation is developed in Launchpad as part of the Percona Toolkit source code.
If you spotted innacuracies, errors, don't understood it or you think something is missing or should be improved, please file a bug.
]]>