Mithilesh Kumar Mithilesh Kumar - 1 year ago 108
MySQL Question

Error in connecting R to MySQL running on Amazon ec2 Ubuntu machine

I have recently configured MySQL on my Amazon EC2 Ubuntu machine. I am trying to connect MySQL db to RStudio running on the same machine. I am using the R package

for the same.

My R-code:

con = dbConnect(MySQL(), user='user1', password='pass1', dbname='db1', host='http://ec2-*********')

The error message:

<script src=""></script>
<script src=""></script>
<script src=""></script>
<script src=""></script>
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Unknown MySQL server host '' (2)

<!-- end snippet -->

Answer Source

You should be able to connect on an Ubuntu machine to a MySQL database using the following:


mySqlCreds <- list(dbhostname = "YourHostIP",
               dbname   = "YourDB",
               username = "YourUserName",
               pass = "YourPassword",
               port = 1111

drv <- dbDriver("MySQL")
dbConnect(drv, host=mySqlCreds$dbhostname, dbname=mySqlCreds$dbname, 
        user=mySqlCreds$username, password=mySqlCreds$pass, port = mySqlCreds$port)

Where of course the port is whichever port you or your DBA has specified...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download