【发布时间】:2011-07-22 20:43:29
【问题描述】:
我正在从RSQLite 移动到RMySQL,我对user 和password 字段感到困惑。 FWIW,我正在运行 Windows 7、R 2.12.2、MySQL 5.5(全 64 位)和 RMySQL 0.7-5。
我按照previous SO question 中的规定安装了RMySQL,据我所知它可以工作(即,我可以使用library(RMySQL) 加载包)。但是当我尝试从R data import guide 运行教程时,我收到“无法连接到数据库...”错误。这是指南中的教程代码:
library(RMySQL) # will load DBI as well
## open a connection to a MySQL database
con <- dbConnect(dbDriver("MySQL"), user = "root", password = "root", dbname = "pookas")
## list the tables in the database
dbListTables(con)
## load a data frame into the database, deleting any existing copy
data(USArrests)
dbWriteTable(con, "arrests", USArrests, overwrite = TRUE)
dbListTables(con)
## get the whole table
dbReadTable(con, "arrests")
## Select from the loaded table
dbGetQuery(con, paste("select row_names, Murder from arrests",
"where Rape > 30 order by Murder"))
dbRemoveTable(con, "arrests")
dbDisconnect(con)
在第二行我收到以下错误:
> con <- dbConnect(dbDriver("MySQL"), user = "richard", password = "root", dbname = "pookas")
Error in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'richard'@'localhost' (using password: NO)
)
我尝试过使用和不使用user 和password 以及管理员作为user。我也尝试过使用我之前在命令行中创建的dbname 和一个不存在的。
有什么建议吗?这里有很好的参考吗?谢谢!
【问题讨论】: