Monday, November 9, 2015


Connect R with MYSQL database

  • Monday, November 9, 2015
  • Share
  • 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


    mydb = dbConnect(MySQL(), user='root', password='root', host='', 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")


    You will get 

    Saswath   Bangalore

    then finally close the connection by


    Results are stored in Dataframe table_values , Now you can write r dataframe code .  RJDBC is easy and simple to connect R with mysql.

    0 Responses to “Connect R with MYSQL database”