Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

MySQLDriver-class

Class MySQLDriver with constructor MySQL.


Description

An MySQL driver implementing the R database (DBI) API. This class should always be initialized with the MySQL() function. It returns a singleton that allows you to connect to MySQL.

Usage

MySQL(max.con = 16, fetch.default.rec = 500)

Arguments

max.con

maximum number of connections that can be open at one time. There's no intrinic limit, since strictly speaking this limit applies to MySQL servers, but clients can have (at least in theory) more than this. Typically there are at most a handful of open connections, thus the internal RMySQL code uses a very simple linear search algorithm to manage its connection table.

fetch.default.rec

number of records to fetch at one time from the database. (The fetch method uses this number as a default.)

Examples

if (mysqlHasDefault()) {
# connect to a database and load some data
con <- dbConnect(RMySQL::MySQL(), dbname = "test")
dbWriteTable(con, "USArrests", datasets::USArrests, overwrite = TRUE)

# query
rs <- dbSendQuery(con, "SELECT * FROM USArrests")
d1 <- dbFetch(rs, n = 10)      # extract data in chunks of 10 rows
dbHasCompleted(rs)
d2 <- dbFetch(rs, n = -1)      # extract all remaining data
dbHasCompleted(rs)
dbClearResult(rs)
dbListTables(con)

# clean up
dbRemoveTable(con, "USArrests")
dbDisconnect(con)
}

RMySQL

Database Interface and 'MySQL' Driver for R

v0.10.21
GPL-2
Authors
Jeroen Ooms [aut, cre] (<https://orcid.org/0000-0002-4035-0289>), David James [aut], Saikat DebRoy [aut], Hadley Wickham [aut], Jeffrey Horner [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.