connecting using SSL (client.flag=2048) to a RDS DB freezes forever
cross-posted, cf https://github.com/r-dbi/RMariaDB/issues/151
Hello, Any comment on this ? I spent a lot of time providing a complete reproducible example with the mysql server and clients configured...
Hello,
To @kforner and all the other poor souls like me fighting to connect using SSL, I did finally manage to connect using the following strategy.
Before proceeding, update the DBI and RMariaDB libraries to the last version using the devtools from within R.
-
obtain the file
rds-combined-ca-bundle.pemhere and save it to disk on your home directory. -
provide a configuration file named
db.conf(or whatever name you prefer) on your home directory having the following content
[connection_name]
database=database_name
host=your_host_address
user=your_user_name
password=your_password
ssl_ca=/path/to/rds-combined-ca-bundle.pem
- connect to the database via DBI and RMariaDB from R:
## install.packages("devtools")
## devtools::install_github("r-dbi/DBI")
## devtools::install_github("r-dbi/RMariaDB")
library(DBI)
library(RMariaDB)
mydb <- dbConnect(
RMariaDB::MariaDB()
,default.file = '/path/to/db.conf'
,group = 'connection_name'
)
## test the connection
dbGetQuery(mydb,'show tables;')
Hope that helps.
Best regards, Rafael R. de Moraes
for what it's worth, here's my connect function:
mysql_connect <- function(..., drv = MariaDB(), ssl = FALSE, ssl.ca = get_rds_ssl_certificates_bundle()) {
#mysql_connect <- function(..., drv = MariaDB()) {
### ... can be a list of params or a list of a list of params
### we make sure to always a list of params
args <- list(...)
if (length(args) == 1 && is.list(args[[1]])) args <- args[[1]]
if (is.null(args$drv)) args$drv <- drv
if (!is.null(args$ssl)) {
ssl <- args$ssl
args$ssl <- NULL
}
# dbConnect has a bug with a relative default.file
if (!is.null(args$default.file)) {
first_char <- substr(args$default.file, 1, 1)
if (first_char != .Platform$file.sep) # relative path
args$default.file <- paste0('.', .Platform$file.sep, args$default.file)
}
if (ssl) {
if (is.null(args$ssl.ca)) args$ssl.ca <- ssl.ca
}
do.call(DBI::dbConnect, args)
}