quinta-feira, 26 de fevereiro de 2015

Connection R to MySQL using RMySQL

You can easily install RMySQL package downloading from the CRAN site with this command:

   install.packages("RMySQL")

To start using RMySQL and extract querys from it:

library(RMySQL) 
mydb = dbConnect(MySQL(), user="mysqluser", password="userpassword", dbname="yourdatabase", host="yourserveripaddressgoeshere") 
rs = dbSendQuery(mydb, "select * from sometable") 
data = fetch(rs, n=-1) 
data

Now you have a variable named "data" that inherits from data.frame with your query results.

Easy as pie... =D


Check out my new book about R Language http://www.amazon.com/dp/B00SX6WA06

Nenhum comentário:

Postar um comentário

Leave your comment here!