Although you can specify user authentication parameters
(user, password, database, and host) in
the call to dbConnect
, the preferred method to pass
these parameters to the server is through a MySQL
default.file
, e.g., $HOME/.my.cnf (or c:/my.cnf
under Windows).
The MySQL dbConnect
method parses the
default.file=$HOME/.my.cnf
to initialize connections to
MySQL databases.
This file consists of zero or more named sections
each starting with a line of the form [section-name]
;
each section includes zero or more MySQL variable declaration per line,
such as, user=
, password=
, host=
, etc.
For instance,$ cat $HOME/.my.cnf
# this is a comment
; this is also a comment
[client]
user = dj
host = localhost
[rs-dbi]
database = s-data
[lasers]
user = opto
database = opto
password = pure-light
host = merced
...
[iptraffic]
host = data
database = iptraffic
This file should be readable only by you. RMySQL
always initializes connection values from the [client]
and
[rs-dbi]
sections, but you may define you own project-specific
sections (as in the example above) to tailor its environment;
if the same parameter appears in multiple sections (e.g., in client
and rs-dbi
), the last (closer to the bottom) occurrence is used.
If you define a section, for instance, [iptraffic]
,
then instead of including all these parameters in the
call to dbConnect
, you simply supply the
name of the group
,
e.g., dbConnect(MySQL(), group = "iptraffic")
.
In addition to user
, password
, host
, and
dbname
, you may specify any other connection parameters,
e.g., port
, socket
. See the MySQL documentation
for details.
Lastly, you may specify an alternate default.file
, e.g.,
dbConnect(MySQL(), group="iptraffic", default.file="router_shield")
.