Create a database object and connect to data base
library(RMySQL)
## Loading required package: DBI
database = dbConnect(MySQL(), user='root', password='Baseball11', dbname='Movies', host='localhost')
dbListTables(database)
## [1] "Movies"
dbListFields(database, 'Movies')
## [1] "Person" "BlackPanther"
## [3] "AvengersInfinityWars" "Incredibles"
## [5] "JurassicWorldFallenKingdom" "Deadpool"
## [7] "QuietPlace"
Retrieve the data from MySQLdb by using a query and save as results
results <- dbSendQuery(database, "select * from Movies")
Fetch results using fetch function and save as db
moviesDB <- fetch(results, n = -1)
moviesDB
## Person BlackPanther AvengersInfinityWars Incredibles
## 1 Brandon M. 4 5 3
## 2 Olivia Y. 3 0 0
## 3 Judi C. 5 4 5
## 4 Ernesto V. 4 5 3
## 5 Stephen S. 5 5 5
## 6 Caitlyn B. 4 0 0
## 7 Murtise F. 5 0 3
## 8 Rod 3 5 5
## 9 Vin 4 5 5
## 10 Marco 0 0 5
## JurassicWorldFallenKingdom Deadpool QuietPlace
## 1 0 4 3
## 2 0 3 0
## 3 4 4 5
## 4 3 4 3
## 5 3 4 0
## 6 0 3 0
## 7 0 0 0
## 8 0 0 0
## 9 0 5 3
## 10 0 0 3