Skip to content

Instantly share code, notes, and snippets.

@HanjoStudy
Created October 8, 2018 08:51
Show Gist options
  • Save HanjoStudy/cec2be012783280378a48d3c90c42bf1 to your computer and use it in GitHub Desktop.
Save HanjoStudy/cec2be012783280378a48d3c90c42bf1 to your computer and use it in GitHub Desktop.
Database_in_R
library(tidyverse)
library(RMySQL)
library(DBI)
library(dbplyr)
db_insert_table <- function(db_name, table_name, df){
db_user <- Sys.getenv("server_user")
db_password <- Sys.getenv("server_pass")
db_host <- "XXX"
db_dbname <- db_name
mydb <-
dbConnect(
MySQL(),
user = db_user,
password = db_password,
dbname = db_dbname,
host = db_host,
port = 3306
)
on.exit(dbDisconnect(mydb))
db_insert_into(mydb, table_name, df)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment