From R running on a Ubuntu machine, I want to connect to a MariaDB living on a Synology NAS and read the table. As the documentation suggests, I do
library(RMariaDB)
con <- dbConnect(
drv=RMariaDB::MariaDB(),
username='<user>',
password='<password>',
host='192.168.1.2',
port=3307,
dbname='foo'
)
but this just fails with the error:
Error: Failed to connect: Lost connection to MySQL server at
'waiting for initial communication packet', system error: 110
The port is correct since otherwise I get
Error: Failed to connect: Can't connect to MySQL server on '
192.168.1.2:<wrongport>' (111)
The driver also appears to be available:
RMariaDB::MariaDB()
# <MariaDBDriver>
Note, that I already installed MariaDB Connector/ODBC and UnixODBC. The database itself is accessible since I am able to connect using RemoDB on Android with the same credentials. Maybe I just missed something basic.
Finally, I would simply like to do this:
dat <- dbReadTable(con)
Specs:
Ubuntu: 20.04.3 LTS
Linux: 5.13.0-27-generic x86_64
mysql: 8.0.27-0ubuntu0.20.04.1
DSM: 7.0.1-42218
phpMyAdmin: 4.9.7-1032
MariaDB 10: 10.3.29-1038
R: 4.1.2
RStudio: 2021.9.0.351
RMariaDB: 1.2.1
odbc: 1.3.3
DBI: 1.1.2
Update
I managed to connect to the database without using RMariaDB::MariaDB()
but using RMySQL::MySQL()
instead1. However, there are two remaining issues:
This answer states, "RMariaDB will be a replacement for RMySQL, so in near future you will not get bug or security fixes for RMySQL anymore." Is this really true? What is now the best way to connect to my MariaDB?
Establishing the connection takes a very long time (see timing below). What could be the issue? I have no clue what could be wrong since there are many steps involved.
system.time(
mydb <- dbConnect(RMySQL::MySQL(), user=db_user, password=db_password,
dbname=db_name, host=db_host, port=db_port)
)
# user system elapsed
# 0.070 0.116 206.902
s <- paste0("select * from ", db_table)
rs <- dbSendQuery(mydb, s)
df <- fetch(rs, n=-1)
on.exit(dbDisconnect(mydb))