Monday, November 9, 2015
0
Connect R with MYSQL database
R is simple and has more features.
In this post we can see how write R code to connect Mysql DB which is installed in azure platform.
I am using R studio .
RJDBC package to connect Mysql.
First install RJDBC by using following command in R studio
Here we are insert records in table and fetch the result by R script
DB name is Department
Table name is Maths
install.packages("RJDBC")
mydb = dbConnect(MySQL(), user='root', password='root', host='jay_hadoop.cloudapp.net', dbname="Department")
To insert value in Maths table
query1=dbGetQuery(mydb, "INSERT INTO Maths (StudentName, City) VALUES ('Saswath','Bangalore');")
then finally close the connection by
dbDisconnect(mydb)
In this post we can see how write R code to connect Mysql DB which is installed in azure platform.
I am using R studio .
RJDBC package to connect Mysql.
First install RJDBC by using following command in R studio
Here we are insert records in table and fetch the result by R script
DB name is Department
Table name is Maths
install.packages("RJDBC")
mydb = dbConnect(MySQL(), user='root', password='root', host='jay_hadoop.cloudapp.net', dbname="Department")
To insert value in Maths table
query1=dbGetQuery(mydb, "INSERT INTO Maths (StudentName, City) VALUES ('Saswath','Bangalore');")
To fetch values from table Maths
table_values <-dbGetQuery(mydb, "select * from Maths")
print(table_values)
You will get
Saswath Bangalore
then finally close the connection by
dbDisconnect(mydb)
Results are stored in Dataframe table_values , Now you can write r dataframe code . RJDBC is easy and simple to connect R with mysql.
Subscribe to:
Post Comments (Atom)
0 Responses to “Connect R with MYSQL database”
Post a Comment