O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using RMySQL

The RMySQL package uses the MYSQL_HOME environment variable to get to the needed libraries:

> dbWriteTable(con, "orders", order) 

The dbWriteTable function inserts records into the table. If the table does not exist, it creates the table. By default, row.names of the data frame is added as a column to the table; if it is not needed, remember to set it to FALSE:

> dbReadTable(con,"accomodation") 

The dbReadTable function reads the table and creates a data frame:

> dbGetQuery(con,"select * from accomodation limit 5") 

The dbGetQuery function executes the query and returns all the results as a data frame. When the table is large, it is better to use the dbSendQuery and fetch results as needed:

> rs <- dbSendQuery(con, "select * ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required