Guest User

Untitled

a guest
Sep 3rd, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. Connect to MySQL database with RMySQL
  2. library(RMySQL) # will load DBI as well
  3. ## open a connection to a MySQL database
  4. con <- dbConnect(dbDriver("MySQL"), user = "root", password = "root", dbname = "pookas")
  5. ## list the tables in the database
  6. dbListTables(con)
  7. ## load a data frame into the database, deleting any existing copy
  8. data(USArrests)
  9. dbWriteTable(con, "arrests", USArrests, overwrite = TRUE)
  10. dbListTables(con)
  11. ## get the whole table
  12. dbReadTable(con, "arrests")
  13. ## Select from the loaded table
  14. dbGetQuery(con, paste("select row_names, Murder from arrests",
  15. "where Rape 30 order by Murder"))
  16. dbRemoveTable(con, "arrests")
  17. dbDisconnect(con)
  18.  
  19. > con <- dbConnect(dbDriver("MySQL"), user = "richard", password = "root", dbname = "pookas")
  20. Error in mysqlNewConnection(drv, ...) :
  21. RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'richard'@'localhost' (using password: NO)
  22. )
Add Comment
Please, Sign In to add comment