Database Reference
In-Depth Information
• Perl DBI and Ruby DBI provide direct API support for reading option files; simply
indicate that you want to use them at the time that you connect to the server. It's
possible to specify that only a particular file should be read, or that the standard
search order should be used to look for multiple option files.
• PHP PDO, Connector/Python, and Java do not support option files. (The PDO
MySQL driver does, but not if you use mysqlnd as the underlying library.) As a
workaround for PHP, we'll write a simple option-file parsing function. For Java,
we'll adopt a different approach that uses properties files.
Although the conventional name under Unix for the user-specific option file
is .my.cnf in the current user's home directory, there's no rule that your own programs
must use this particular file. You can name an option file anything you like and put it
wherever you want. For example, you might set up a file named mcb.cnf and install it
in the /usr/local/lib/mcb directory for use by scripts that access the cookbook database.
Under some circumstances, you might even want to create multiple option files. Then,
from within any given script, select the file that's appropriate for the access privileges
the script needs. For example, you might have one option file, mcb.cnf , that lists pa‐
rameters for a full-access MySQL account, and another file, mcb-readonly.cnf , that lists
connection parameters for an account that needs only read-only access to MySQL. An‐
other possibility is to list multiple groups within the same option file and have your
scripts select options from the appropriate group.
Perl. Perl DBI scripts can use option files. To take advantage of this, place the appropriate
option specifiers in the third component of the data source name (DSN) string:
• To specify an option group, use mysql_read_default_group= groupname . This tells
MySQL to search the standard option files for options in the named group and in
the [client] group. Write the groupname value without the surrounding square
brackets. (If a group in an option file begins with a [my_prog] line, specify the
groupname value as my_prog .) To search the standard files but look only in the
[client] group, groupname should be client .
• To name a specific option file, use mysql_read_default_file= filename in the
DSN. When you do this, MySQL looks only in that file and only for options in the
[client] group.
• If you specify both an option file and an option group, MySQL reads only the named
file, but looks for options both in the named group and in the [client] group.
The following example tells MySQL to use the standard option-file search order to look
for options in both the [cookbook] and [client] groups:
my $conn_attrs = { PrintError => 0 , RaiseError => 1 , AutoCommit => 1 };
# basic DSN
Search WWH ::




Custom Search