CS MySQL question
--- title: "MySQL" author: "Kathleen" date: "3/11/2019" output: pdf_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. ```{r connect} library(DBI) # Connect to my-db as defined in ~/.my.cnf con <- dbConnect(drv=RMySQL::MySQL(), username = "root", password="rootroot" ,host="127.0.0.1" ,port = 3306, dbname="lotrfinal") dbListTables(con) # You can fetch all results: res <- dbSendQuery(con, "SELECT * FROM lotr_character") chunk <- dbFetch(res, 10) print(nrow(chunk)) print(chunk) dbClearResult(res) # Disconnect from the database dbDisconnect(con) ``` ## Including Plots You can also embed plots, for example: ```{r pressure, echo=FALSE} plot(pressure) ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.