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
Related
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.
I am trying to connect with MySQL from R (version R-3.3.3). Unfortunately, I get the error. I tried to change the version to R-3.4.0 but the error is persistent.
library(DBI)
library(RMySQL)
db <- dbConnect(MySQL(), dbname = "example", host = "localhost",
port = 3306, user = "root",
password = "****")
Error: Error in .local(drv, ...) : Failed to connect to database:
Error: Lost connection to MySQL server at 'reading authorization
packet', system error: 10060
Please help!
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.
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.
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)