Acces denied MariaDB Amazon-rds instance RMySQL and OBDC (windows) - r

I'm trying to connect R with my MariaDB instance (10.0 - Amazon RDS). Connection works fine in HeidiSQL. Both in R and ODBC drivers installation (direct and indirect), next error is prompted:
Error in .local(drv, ...) :
Failed to connect to database: Error: Access denied for user 'user'#'localhost' (using password: YES)
My account is the admin account of this instance, I used the following code:
library(RMySQL)
mySqlCreds <- list(dbhostname = "dbname.rds.amazonaws.com" , dbname="dbnamefull" , username = "user",pass = "secret", port = 3306)
drv <- dbDriver("MySQL")
dbConnect(drv, host=mySqlCreds$dbhostname, dbname=mySqlCreds$dbname, user=mySqlCreds$username, password=mySqlCreds$pass, port = mySqlCreds$port)
Same problem while connecting an ODBC driver in Windows to this instance- finds database, but again no access. Even after modifying instance parameter groups in aws console, log_bin_trust_function_creators to 1, and rebooting the database.
If you know how to solve this issue, please let me know! Thank you in advance!

Related

How to resolve "Error: could not receive data from server" - database connection in r?

I am running into
Error: could not receive data from server: Software caused connection abort (0x00002745/10053)
upon trying to connect to a postgres database using the DBI package in R. Note that i am in a work environment, so subject to a corporate firewall. Can that explain the error or is there something else that could be happening?
Here is the code I'm using
# Connect to trayaway dev
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = host, port = 5432, dbname = "postgres",
user = user, password = password
)
error below:
Error: could not receive data from server: Software caused connection abort (0x00002745/10053)
solution was found- i tried the same code using wiFi and the code works - when hardwired, connection string fails to connect to database - so this is a corporate firewall issue - thank you,

connect to oracle database which located on other ip using R

I need connect to oracle database via R
I do so
library(RODBC)
library(RJDBC)
odbcConnect(dsn = "NBD-TEST-DEV-BLACKBOX",
uid = "Y", pwd = "X")
i use oracle sql developer client to get access
When i try connect via R
i get the errors
Warning messages:
1: In RODBC :: odbcDriverConnect ("DSN = NBD-TEST-DEV-BLACKBOX; UID = x; PWD = y"):
[RODBC] ERROR: state IM002, code 0, message [Microsoft] [ODBC Driver Manager] Data source not found and no default driver used
2: In RODBC :: odbcDriverConnect ("DSN = NBD-TEST-DEV-BLACKBOX; UID = x; PWD = y"):
ODBC connection failed
i think it becase the database on another IP (R on server which ip x.x.x.x, and oracle on IP Y.y.y.y
So i have two questions
how can i indicate path to ODBC , where it. My oracle sql developer in path "C:\Users\Admin\Desktop\sqldeveloper-19.1.0.094.2042-x64"
and how to indicate needed IP when connect

setting property in odbc

I wonder how I can set domain to a value when I am trying to connect to a SQL database in R.
Basically, I need to set Domain to cphegtd3 to be able to get to the database.
I am using the
con <- dbConnect(odbc(),
Driver = "/usr/local/lib/libtdsodbc.so",
Server = "servername",
Database = "dbname",
UID = "myuserid",
PWD = "London",
Domain="cphegtd3",
Port = 1433)
and I get the following error
Error: nanodbc/nanodbc.cpp:950: 42000: [unixODBC][FreeTDS][SQL Server]Login failed for user 'myuserid'.
The reason it fails the username is that it does not consider Domain="cphegtd3". I didn't have this issue with RSQLServer::SQLServer() and domain was an entry in the yaml file.
I can also connect to the database through DBeaver and DataGrip, and of course have to set domain in the setting. But I don't know how to inform odbc in R with this parameter.

PostgreSQL dbConnect to shiny app in ec2 instance

I have an ec2 instance set up with my shiny app and my postgresql database, I want to get the shiny-app to read from the database
If I type psql and \conninfo while ssh-ed into my instance I get
You are connected to database "ubuntu" as user "ubuntu" via socket in "/var/run/postgresql" at port "5432".
When I use R in the ec2 command line and type the following, I can read from my database no problem!
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname = "ubuntu", host = "/var/run/postgresql", port = 5432, user = "ubuntu", password = pw)
However, when I put these same lines in my shiny app.R file I get
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect ubuntu#/var/run/postgresql:5432 on dbname "ubuntu": FATAL: Peer authentication failed for user "ubuntu")
I've tried so many different values for host like
host = "localhost"
host = "my ec2 public ip address"
host = "127.0.0.1"
for example and nothing has been working.
my security group for this ec2 instance has an inboud connection to port 5432.
could this be it: why is one file green and the other pink? the green one is the one that works (local) and the pink one is on my instance
Finally figured it out.. this is the same problem as Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails
except that I was getting a different error for the same underlying problem.
the answer that worked for me is the second one:
1.
nano /etc/postgresql/9.x/main/pg_hba.conf
change peer in this line
local all postgres peer
to
local all postgres trust
Restart the server
sudo service postgresql restart
Login into psql and set your password
psql -U postgres
ALTER USER postgres with password 'your-pass';
Finally change the pg_hba.conf from
local all postgres trust
to
local all postgres md5
and that finally worked

Connect to MySQL database with RMySQL

I am making the move from RSQLite to RMySQL and I am confused by the user and password fields. FWIW, I'm running Windows 7, R 2.12.2, MySQL 5.5 (all 64 bit), and RMySQL 0.7-5.
I installed RMySQL as prescribed in this previous SO question, and as far as I know it works (i.e., I can load the package with library(RMySQL)). But when I try to run the tutorial from the R data import guide, I get a "failed to connect to database..." error. This is the code from the tutorial from the guide:
library(RMySQL) # will load DBI as well
## open a connection to a MySQL database
con <- dbConnect(dbDriver("MySQL"), user = "root", password = "root", dbname = "pookas")
## list the tables in the database
dbListTables(con)
## load a data frame into the database, deleting any existing copy
data(USArrests)
dbWriteTable(con, "arrests", USArrests, overwrite = TRUE)
dbListTables(con)
## get the whole table
dbReadTable(con, "arrests")
## Select from the loaded table
dbGetQuery(con, paste("select row_names, Murder from arrests",
"where Rape > 30 order by Murder"))
dbRemoveTable(con, "arrests")
dbDisconnect(con)
On the second line I get the following error:
> con <- dbConnect(dbDriver("MySQL"), user = "richard", password = "root", dbname = "pookas")
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'richard'#'localhost' (using password: NO)
)
I have tried with and without user and password and with admin as user. I have also tried using a dbname that I made before with the command line and with one that doesn't exist.
Any tips? Is there a good reference here? Thanks!
That is most likely a setup issue on the server side. Make sure that networked access is enabled.
Also, a local test with the command-line client is not equivalent as that typically uses sockets. The mysql server logs may be helpful.
First try to connect to MySQL server using MySQL Workbench or command line mysql using the same parameter. If it connects then R should also be able to connect.
Typically this issue comes when MySQL server doesn't allow connections from remote machines.
As people have told you, you can try to connect to the host with other application as mysql workbench. How odd! When I have tried in RStudio to connect to my db with your code without indicate the host in the command I haven't been able to connect.
I have needed to indicate the host ( host = 'localhost' ) in the command.

Resources