Connect to local database from phpmyadmin using R

I have searched many threads explaining database communication with R, but I still cannot get it to work.

At this point I know that I need to install the "ROBDC" package and use either odbcConnect()

or odbcDriverConnect()

. But the first one seems trickier as I have to establish an OBDC connection (tried some things but didn't work too tt).

My end goal is to fetch some data in a database located on a web server, but first, I wanted to see how these functions work for a local database created with Wamp Server. I am currently working on Windows 7.

My database name is "fetch" and id is "root" (no pwd usually), so I wrote:

install.packages('RODBC',repos="http://cran.rstudio.com/")

odbcDriverConnect(Driver='mysql'; Server=localhost;
Database=extraction; Uid='root'; pwd='')

      

I don't know if the syntax is correct, I tried a lot and always the same error as drivers and data source is unreachable.

Here's the full post (in French sorry D :)


"[RODBC] ERROR: Status IM002, Code 0, Message [Microsoft] [Gestionnaire de pilotes ODBC] Source de données introuvable et nom de pilote non spécifié"


I used this function to avoid the dns thing required for obdcConnect()

, but still I don't know if I'm doing the right thing (obvsly not, since it doesn't work: D), but this is my first time with R to interact with bases data, so I don't know where to go even with all the help I was looking for.

Thanks in advance.

+1


source to share


1 answer


Well I found a solution with a package called RMySQL



install.packages('RMySQL')
require(RMySQL) #if already installed
con <- dbConnect(RMySQL::MySQL(), host = "localhost",dbname="extraction",user = "root", password = "")
test_extraction <- dbReadTable(con, "utilisateurs") #utilisateurs is a table from my database called extraction

      

0


source







All Articles