使用R从phpmyadmin连接到本地数据库 [英] Connect to a local database from phpmyadmin with R

查看:92
本文介绍了使用R从phpmyadmin连接到本地数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多线程来解释与具有R的数据库的连接,但是我仍然无法使其正常工作.

I have searched for a lot of threads explaining the connexion with a database with R but I still can't make it work.

此刻,我知道我必须安装软件包'ROBDC'并使用odbcConnect()odbcDriverConnect().但是第一个似乎更困难,因为我必须设置OBDC连接(尝试了一些操作,但在t.t上却无法正常工作).

At the moment, I know that I have to install the package 'ROBDC' and use either odbcConnect() or odbcDriverConnect(). But the first one seems harder since I have to set an OBDC connection (tried some things but didn't work too t.t).

我的最终目标是在位于Web服务器上的数据库中提取一些数据,但是,首先,我想了解这些功能如何用于使用Wamp Server创建的本地数据库.我目前正在Windows 7上工作.

My final goal is to extract some data in a database located in a web server but, first, I wanted to see how the functions work for a local database created with Wamp Server. I'm currently working on Windows 7.

我的数据库的名称是'extraction',而id是'root'(通常没有密码),所以我写道:

My database's name is 'extraction' and the 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 have tried a lot and always the same error with drivers and data source unobtainable.

这里是完整的消息(以法语对不起,D:)

Here the full message (in French sorry D:)

"[[RODBC]错误:状态IM002,代码0,消息[Microsoft] [飞行员ODBC语法]无法解释的源代码和非专家术语"

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


我使用此功能来避免obdcConnect()所需的dns事情,但是我仍然不知道我是否在做正确的事情(显然不是因为他不工作:D),但这是我第一次尝试使用R与数据库进行交互,因此即使我一直在寻找所有帮助,我也不知道该去哪里.


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 he doesn't work :D) but it's my first time trying with R to interact with databases so I don't know where to go even with all the help I have looked for.

谢谢.

推荐答案

好吧,我找到了一个名为RMySQL的程序包

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

这篇关于使用R从phpmyadmin连接到本地数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆