使用RMySQL连接MySQL数据库

Ric*_*ron 12 r rmysql

我正在从移动RSQLiteRMySQL,我被迷惑userpassword领域.FWIW,我正在运行Windows 7,R 2.12.2,MySQL 5.5(全部64位)和RMySQL 0.7-5.

RMySQL按照之前的SO问题安装,据我所知,它可以工作(即,我可以加载包library(RMySQL)).但是当我尝试从R数据导入指南运行教程时,我收到"无法连接到数据库..."错误.这是指南教程中的代码:

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)
Run Code Online (Sandbox Code Playgroud)

在第二行,我收到以下错误:

> 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)
)
Run Code Online (Sandbox Code Playgroud)

我曾尝试使用和不使用userpassword管理员user.我也尝试使用dbname我之前使用命令行创建的,并使用不存在的.

有小费吗?这里有好的参考吗?谢谢!

Dir*_*tel 5

这很可能是服务器端的设置问题.确保已启用网络访问.

此外,使用命令行客户端进行本地测试等同于通常使用套接字的测试.mysql服务器日志可能会有所帮助.