Accessing data in MySQL databases by using the RMariaDB library

The RMariaDB library is preinstalled RStudio environments by default. If your data is stored in a MySQL database and you want to use RMySQL functions to query this data, you can use this library.

The following code snippet shows how to install the package and use some basic library functions to connect to a MySQL database and query data:

# Install the package

library ('RMariaDB')

# Connect to a remote database with your username and password

con <- dbConnect(RMariaDB::MariaDB(),host="<url_of_db_server>,user="<your_username>",password="<your_password>",dbname='my_sql_db')

dbListTables(con)

dbGetQuery(con, "SELECT * FROM customers_csv")

# Always clean up by disconnecting the database

dbDisconnect(con)

Learn more about other RMariaDB library functions: Package RMariaDB

Parent topic: RStudio