I am using parallel querying with RMySQL
. Is it possible to share the connection between workers?
library(foreach)
library(doParallel)
library(RMySQL)
con <- dbConnect(MySQL(),
user = 'user',
password = 'password',
host = 'someip',
dbname = 'test01')
numCores <- detectCores()
registerDoParallel(numCores)
foreach (i=1:3,.packages='RMySQL') %dopar% {
dbGetQuery(con,paste0("INSERT INTO t VALUES ('Some Text')"))
}
dbDisconnect(con)
I got this error:
Error in { : task 1 failed - "Corrupt MySQL handle"
Is it possible to share the connection between workers?
No, the connection maintains state of the progress of the query and its results. A separate connection per worker is required.