Question

I am trying to read data from a MySQL database using the following code:

drv<-dbDriver("MySQL")
user<-'xxxx'
password<-'xxxx'
dbname<-'test'
con<-dbConnect(drv, user=user, password=password, dbname=dbname)

load.packages('quantmod')   
tickers = 'Z (Dec 10)'
setDefaults(getSymbols,verbose=T,src='MySQL')

data <- new.env()

data = getSymbols(tickers,  from = '2010-09-01', env = data, auto.assign = T)

which generates the following error:

> data = getSymbols(tickers,  from = '2010-09-01', env = data, auto.assign = T)
Error in getSymbols.MySQL(Symbols = "Z (Dec 10)", env = <environment>,  :
  At least one connection argument ( ‘user’ ‘password’ ‘dbname’ ) is not set

I don't understand why when I have setup the con, it is not working.

Was it helpful?

Solution

getSymbols.MySQL() does the connection for you. I.e. you give user, password and dbname to it, and don't worry about anything else.

I don't know if it does connection caching. If it doesn't, and that affects performance, then use the dbi functions directly to read your data into xts objects, and don't use this quantmod high-level functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top