mysql - 从 R 从 MySQL 加载大数据
问题描述
我在 MySQL 中有一个大表(大约 300 万行,15 列),我正在尝试在 R 闪亮应用程序中使用表中的一些数据。
我已经能够获得连接并在 R 中编写查询:
library(DBI)
library(dplyr)
cn <- dbConnect(drv = RMySQL::MySQL(),
username = "user",
password = "my_password",
host = "host",
port = 3306
)
query = "SELECT * FROM dbo.locations"
然而,当我运行dbGetQuery(cn, query)
它需要很长时间(我最终关闭了我的 RStudio 程序,因为它变得无响应。
我也试过
res <- DBI::dbSendQuery (cn, query)
repeat {
df <- DBI::dbFetch (res, n = 1000)
if (nrow (df) == 0) { break }
}
dbClearResult(dbListResults(cn)[[1]])
因为这类似于按块读取数据,但由于df
某种原因,我的结果有 0 行。
关于如何在 R 中获取我的表的任何建议?我什至应该尝试将该表读入 R 吗?据我了解,R 不能很好地处理大数据。
解决方案
推荐阅读
- javascript - 测试一个结合 Observables 的函数
- elasticsearch - 所有索引在 ElasticSearch 中突然被删除
- java - 在 spark java 中创建和管理 jdbc 连接的正确方法
- c++ - 私有包括头文件
- javascript - 如何使用 Typescript 在 React 中创建依赖下拉列表?
- python - 无法在 df.plot 的 x 轴上绘制日期
- react-native - 关于 React-native 的 Global AwesomeAlert
- ruby-on-rails - Rails 在多态中使用状态机
- python - 在熊猫数据框中选择列
- sql-server - 名为“tds_cur”的游标不存在