RMySQL v0.10.13


Monthly downloads



by Jeroen Ooms

Database Interface and 'MySQL' Driver for R

A 'DBI' interface to 'MySQL' / 'MariaDB'. The 'RMySQL' package contains an old implementation based on legacy code from S-PLUS which being phased out. A modern 'MySQL' client based on 'Rcpp' is available from the 'RMariaDB' package on 'Github': <https://github.com/rstats-db/RMariaDB>.



NOTE: this package is being phased out in favor of the new RMariaDB package.

Database Interface and MySQL Driver for R

Build Status AppVeyor Build Status CRAN_Status_Badge CRAN RStudio mirror downloads Coverage Status

RMySQL is a database interface and MySQL driver for R. This version complies with the database interface definition as implemented in the package DBI 0.2-2.

Hello World

# Connect to my-db as defined in ~/.my.cnf
con <- dbConnect(RMySQL::MySQL(), group = "my-db")

dbWriteTable(con, "mtcars", mtcars)

dbListFields(con, "mtcars")
dbReadTable(con, "mtcars")

# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")

# Or a chunk at a time
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
  chunk <- dbFetch(res, n = 5)
# Clear the result

# Disconnect from the database


Binary packages for OS-X or Windows can be installed directly from CRAN:


The development version from github:

# install.packages("devtools")

Installation from source on Linux or OSX requires MariaDB Connector/C. On some older platforms you can also link against Oracle's libmysqlclient driver but the mariadb implementation is much better.

On recent Debian or Ubuntu install libmariadb-client-lgpl-dev. In Ubuntu 14.04 this was called libmariadbclient-dev.

sudo apt-get install -y libmariadb-client-lgpl-dev

On Fedora, CentOS or RHEL we need mariadb-devel:

sudo yum install mariadb-devel

On OS-X use mariadb-connector-c from Homebrew:

brew install mariadb-connector-c

MySQL configuration file

Instead of specifying a username and password in calls to dbConnect(), it's better to set up a MySQL configuration file that names the databases that you connect to most commonly. This file should live in ~/.my.cnf and look like:


If you want to run the examples, you'll need to set the proper options in the [rs-dbi] group of any MySQL option file, such as /etc/my.cnf or the .my.cnf file in your home directory. For a default single user install of MySQL, the following code should work:



Many thanks to Christoph M. Friedrich, John Heuer, Kurt Hornik, Torsten Hothorn, Saikat Debroy, Matthew Kelly, Brian D. Ripley, Mikhail Kondrin, Jake Luciani, Jens Nieschulze, Deepayan Sarkar, Louis Springer, Duncan Temple Lang, Luis Torgo, Arend P. van der Veen, Felix Weninger, J. T. Lindgren, Crespin Miller, and Michal Okonlewski, Seth Falcon and Paul Gilbert for comments, suggestions, bug reports, and patches.

Functions in RMySQL

Name Description
dbDataType,MySQLDriver-method Determine the SQL Data Type of an S object
dbEscapeStrings Escape SQL-special characters in strings.
dbColumnInfo,MySQLConnection-method Experimental dbColumnInfo method for a connection
dbConnect,MySQLDriver-method Connect/disconnect to a MySQL DBMS
MySQLResult-class Class MySQLResult
constants Constants
db-meta Database interface meta-data
dbApply Apply R/S-Plus functions to remote groups of DBMS rows (experimental)
MySQLConnection-class Class MySQLConnection.
MySQLDriver-class Class MySQLDriver with constructor MySQL.
isIdCurrent Check if a database object is valid.
make.db.names,MySQLConnection,character-method Make R/S-Plus identifiers into legal SQL identifiers
result-meta Database interface meta-data.
dbQuoteIdentifier,MySQLConnection,character-method Quote method for MySQL identifiers
dbReadTable,MySQLConnection,character-method Convenience functions for importing/exporting DBMS tables
dbUnloadDriver,MySQLDriver-method Unload MySQL driver.
dbWriteTable,MySQLConnection,character,data.frame-method Write a local data frame or file to the database.
mysqlBuildTableDefinition Build the SQL CREATE TABLE definition as a string
mysqlClientLibraryVersions MySQL Check for Compiled Versus Loaded Client Library Versions
mysqlHasDefault Check if default database is available.
dbFetch,MySQLResult,numeric-method Execute a SQL statement on a database connection.
transactions DBMS Transaction Management
dbGetInfo,MySQLDriver-method Get information about a MySQL driver.
dbNextResult Fetch next result set from an SQL script or stored procedure (experimental)
No Results!

Last month downloads


License GPL-2
URL https://downloads.mariadb.org/connector-c/ (upstream)
BugReports https://github.com/rstats-db/rmysql/issues
SystemRequirements libmariadb-client-dev | libmariadb-client-lgpl-dev | libmysqlclient-dev (deb), mariadb-devel (rpm), mariadb | mysql-connector-c (brew), mysql56_dev (csw)
NeedsCompilation yes
Collate 'mysql.R' 'driver.R' 'connection.R' 'data-type.R' 'default.R' 'escaping.R' 'result.R' 'extension.R' 'is-valid.R' 'table.R' 'transaction.R'
Packaged 2017-08-14 16:00:27 UTC; jeroen
Repository CRAN
Date/Publication 2017-08-14 18:34:42 UTC

Include our badge in your README