Exemplo de Conexão com RStudio em Mysql

Segue um exemplo prático de obtenção de dados do Banco Mysql usando R

#install.packages(“dbConnect”,type=”source”)
library(RMySQL)
library(dbConnect)

con = dbConnect(MySQL(), user=’user’, password=’passwrd’, dbname=’SMSdb’, host=’192.168.1.211′)

dbListTables(con)

#Create table in R from Mysql table
myQuery = “select * from jobs”

str(df)

telefone= “16981434112”

#my_d_query=paste(“select * from jobs where telefone = ‘”,telefone,”‘ “)
my_d_query=paste(“select * from jobs “)
out_df= dbGetQuery(con,my_d_query)

dbWriteTable(con,”out_df”,out_df, overwrite=TRUE, append=FALSE)
dbDisconnect(con)