daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Sep 3rd, 2018 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top