RMySQL icon indicating copy to clipboard operation
RMySQL copied to clipboard

connecting using SSL (client.flag=2048) to a RDS DB freezes forever

Open kforner opened this issue 6 years ago • 3 comments

cross-posted, cf https://github.com/r-dbi/RMariaDB/issues/151

kforner avatar Jan 17 '20 11:01 kforner

Hello, Any comment on this ? I spent a lot of time providing a complete reproducible example with the mysql server and clients configured...

kforner avatar Jan 27 '20 12:01 kforner

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.

  1. obtain the file rds-combined-ca-bundle.pem here and save it to disk on your home directory.

  2. 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
  1. 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

hafermoraes avatar Mar 10 '21 15:03 hafermoraes

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)
}

kforner avatar Mar 11 '21 08:03 kforner