Created
October 8, 2018 08:51
-
-
Save HanjoStudy/cec2be012783280378a48d3c90c42bf1 to your computer and use it in GitHub Desktop.
Database_in_R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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