将MySQL数据库中的表读入R中

时间:2017-08-31 15:17:33

标签: mysql r r-dbi

我尝试使用R中的DBI包从我的数据库中读取表格:

mydb = dbConnect(MySQL(), user='root', password='*******', dbname='powercurve', host='127.0.0.1')

dbReadTable(mydb,"3.4m140sco")

但显然R中不允许使用表名,因为我收到错误:

Error in .local(conn, statement, ...) : 

could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '3.4m140sco' at line 1

如果在MySQL数据库中我将​​该表的名称更改为table1,那么我可以轻松地在R中读取它。

有人可以帮助我如何在R中读取这些表格,因为显然我无法更改所有表格的名称。

1 个答案:

答案 0 :(得分:2)

反叛可以解决这个问题吗?

dbReadTable(mydb,"`3.4m140sco`")