R ODBC: odbc::odbcListColumns doesn't list columns - mysql

I fully configured ODBC on Linux Ubuntu 20.04.
R can perfectly connect to the datasource but then it cannot even list columns:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "MySQL ODBC 8.0 Driver",
Server = "127.0.0.1",
UID = "root",
PWD = "password",
Port = 3306,
database = "mydb",
)
odbc::odbcListColumns(con, table = "mytable")
Error:
Error in connection_sql_columns(connection#ptr, table_name = validateObjectName(table, :
null access
I'm using this documentation page: https://db.rstudio.com/r-packages/odbc/
Any ideas?

Related

R - Error trying to connect to a MySQL server

I'm trying to connect to a MySQL database using this code:
con <- dbConnect(RMySQL::MySQL(),
dbname = "XX",
host = "YY",
port = ZZ,
user = "AA",
password = "BB"
)
And I'm getting this error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'YY' (0)
I've tried with this other code:
pool <- dbPool(drv = RMySQL::MySQL(),
dbname = "XX",
host = "YY",
username = "AA",
password = "BB",
port = ZZ
)
And get the same error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'YY' (0)
I can connect to this database using Workbench, so I guess it's a problem with R.
Any solution to this problem?
Edit: something I didn't say, the server is remote, so I had to use a SSH key to make the tunnel to the server to be able to access from Workbench. So maybe this should be considered to solve the issue.

How to connect to sql database located locally in r shiny

I am trying to connect to SQL database located in the same directory as in my app.R file but I get the following error if I try to connect.
con <- dbConnect(RMySQL::MySQL(), dbname = "super_data")
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)
mydb = dbConnect(MySQL(), user='root', password='', dbname='super_data.sql', host='localhost')
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)
Try with the following code:
conn <- RMySQL::dbConnect(RMySQL::MySQL(),
user = "root",
password = "mypassword",
dbname = "mydatabase",
host = "127.0.0.1", # Instead of localhost
port = 3306) # Default MySQL port
Hope this can help

Cannot connect to MySql through R. (Error with host argument)

I opened SQL clicked on the database I wanted (named bb) then at the top I choose Database then Manage Connections. This showed me the Hostname as 127.0.0.1, port as 3306, username as root and there should be no password. Plugged that into to dbConnect and it is giving the following errors
This is the code I have and I am trying to open a connection.
> con <- dbConnect(RMySQL::MySQL(), dbname = "bb", username = "root", host =
"127.0.0.1:3306")
Error in .local(drv, ...) :
Failed to connect to database: Error: Unknown MySQL Server Host
'127.0.0.1:3306' (11001)
> con <- dbConnect(RMySQL::MySQL(), dbname = "bb", username = "root", host =
"127.0.0.1", port = 3306)
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on
'127.0.0.1' (0)
> con <- dbConnect(RMySQL::MySQL(), dbname = "bb", username = "root", host =
"127.0.0.1", port = "3306")
Error in .local(drv, ...) : Argument port must be an integer value
All of them are returning errors. I don't know why it is not working.
Please Help and Thank you.

RMySQL does not work as part of a script

When I run
library(RMySQL)
mydb = dbConnect(MySQL(), user = "XX", password = "XX", dbname = "XX", host = "XX")
on the R console it works,
however when I put save it as a yy.R file and run it as R CMD BATCH yy.R, or as source("yy.R") it says
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Can't connect to MySQL server on 'XX' (111)
)
Calls: dbConnect -> dbConnect -> mysqlNewConnection -> .Call
Execution halted
could I check if RMySQL only runs on the console? Thanks!
Perhaps you can specify the driver with RMySQL::MySQL(), this works for me in scripts.

AWS RDS: mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'databasetest.us-east-1.rds.amazonaws.com' (110)")

I have this code below to connect to a rds instance.
But Im having this error:
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'databaseTest.us-east-1.rds.amazonaws.com' (110)")
Do you see anything wrong with the code?
import boto.rds
import MySQLdb
instanceID = "databaseTest"
username = "root"
password = "pass"
getDBEndpoint = conn.get_all_dbinstances(instance_id=instanceID)[0].endpoint
dbEndpoint = getDBEndpoint[0]
conn = MySQLdb.connect(host=dbEndpoint,user=username,passwd=password, db = dbName, port = 3306)
I created the db instance like this:
db = conn.create_dbinstance(instanceID,dbSize,instanceType, username, password, port = instancePort, engine=dbEngine, db_name = dbName)