[R] RMySQL...Can't initialize driver???

Rainer M Krug rkrug at sun.ac.za
Tue Jun 27 15:25:47 CEST 2006


Stephane Cruveiller wrote:
> Duncan Murdoch wrote:
>> On 6/27/2006 8:51 AM, Stephane Cruveiller wrote:
>>> Dear R users,
>>>
>>> I would like to query a MySQL database through R. I have installed
>>> the latest required packages (RMySQL and DBI) in R (v2.3.1). A MySQL
>>> server (v5.0.22) is running on my local machine but I can't
>>> initialize MYSQL
>>> driver:
>>> ------------------------------------------------------------------------------------
>>>
>>>  > library("RMySQL")
>>> Loading required package: DBI
>>>  > MySQL(max.con = 10, fetch.default.rec = 500, force.reload = F)
>>> Error in new("MySQLDriver", Id = drvId) : unused argument(s) (Id ...)
>>> -------------------------------------------------------------------------------------
>>>
>>>
>>> Could somebody tell me what I have missed?

I am running R 2.3.0 under Linux and connect to a MySQl 4.1 server.

You have to create a file in your home directory which has the
connection infos. It should look like that:

				
[renpatch]
user = UserName
password = PassWord
database = ...
host = ...

[renpatch_renosterbos]
user = UserName
password = PassWord
database = ...
host = ..

and be called .my.conf

Then you do:


library("RMySQL")
m <- dbDriver("MySQL")
con <- dbConnect(m, group = "renpatch")
q <- TheSQLQuery
rs <- dbSendQuery(con, q)
TheResults <- fetch(rs, n = -1)
dbDisconnect(con)
rm(con)


and it should work - at least that is what it is doing for me.

Rainer

-- 
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology and Entomology
University of Stellenbosch
Matieland 7602
South Africa

Tel:		+27 - (0)72 808 2975 (w)
Fax:		+27 - (0)21 808 3304
Cell:		+27 - (0)83 9479 042

email:	RKrug at sun.ac.za
      	Rainer at krugs.de



More information about the R-help mailing list