Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connect to MySQL database with RMySQL
- library(RMySQL) # will load DBI as well
- ## open a connection to a MySQL database
- con <- dbConnect(dbDriver("MySQL"), user = "root", password = "root", dbname = "pookas")
- ## list the tables in the database
- dbListTables(con)
- ## load a data frame into the database, deleting any existing copy
- data(USArrests)
- dbWriteTable(con, "arrests", USArrests, overwrite = TRUE)
- dbListTables(con)
- ## get the whole table
- dbReadTable(con, "arrests")
- ## Select from the loaded table
- dbGetQuery(con, paste("select row_names, Murder from arrests",
- "where Rape 30 order by Murder"))
- dbRemoveTable(con, "arrests")
- dbDisconnect(con)
- > con <- dbConnect(dbDriver("MySQL"), user = "richard", password = "root", dbname = "pookas")
- Error in mysqlNewConnection(drv, ...) :
- RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'richard'@'localhost' (using password: NO)
- )
Add Comment
Please, Sign In to add comment