I am trying to connect Mariadb with my R shinny application in Rstudio. I created a Mariadb using docker-compose.yml and now I am trying to access the mariadb container using
library(RMariaDB)
library(DBI)
library(RMySQL)
# Connect to my-db as defined in ~/.my.cnf
drv <- dbDriver("MySQL")
con <- dbConnect(RMySQL::MySQL(),
host="mariadb://root@localhost:3306",
port=3306,
user="",
password="root")
above mentioned code but its not working its giving me error
Failed to connect to database: Error: Can’t connect to local server through socket ‘/tmp/mysql.sock’
and
Failed to connect to database: Error: Plugin mariadb could not be loaded:
Does anyone help that what I am doing wrong here or how I can connect to mariadb properly.
I looked for tutorials but I couldn’t find any which explain mariadb with R. if anyone know any tutorial or link which can explain it kindly let em know. Thanks
2
Answers
Install MariaDB Client Library
sudo apt-get install libmariadb-client-lgpl-dev
Specify MariaDB Client Library Path in R code –
Check RMySQL Compatibility:
Ensure that the version of RMySQL you are using is compatible with your R version and MariaDB version.
Check System Environment Variables –
Verify that the necessary environment variables are set correctly. This may include LD_LIBRARY_PATH on
Sys.getenv("LD_LIBRARY_PATH")
Sys.getenv("DYLD_LIBRARY_PATH")
Restart R Session
When MariaDB is in a compose, its not accessed via localhost. Unix sockets aren’t shared between containers.
Should be:
Assuming your compose service called it mariadb.