RMySQL - My querys return a list

0

Hello, I'm working with a database that I usually access with the workbench. To start importing directly into R, I'm using the RMySQL library. I can make the connection and find my tables, but at the time of importing with tbl it returns me a list. How can I make it return me a df (object table1 in the example)?

Example:

con <- src_mysql(dbname = "dbname", 
                          host = "localhost", 
                          port = 3306, 
                          user = "user",
                          password = "my password")

tabela1 <- tbl(con, "tabela1")

I also tried the dbReadTable command, but it returns me an error message:

*Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘dbReadTable’ for signature ‘"src_dbi", "character"’*

Thanks for the help!

    
asked by anonymous 12.12.2018 / 21:16

2 answers

0

I've never used this package. But the DBI package works for me:

con <- DBI::dbConnect(dbname = "dbname", 
                          host = "localhost", 
                          port = 3306, 
                          user = "user",
                          password = "my password")

tabela1 <- tbl(con, "tabela1")
    
12.12.2018 / 23:08
0

I was able to solve my problem!

library(RMySQL)
library(dbplyr)


conexao <- dbConnect(RMySQL::MySQL(),
                     dbname = "name",
                     host = "localhost",
                     port = 3306,
                     user = "user",
                     password = "my password")


# Encontrar uma tabela em duas etapas:

rs <- dbSendQuery(conexao, "SELECT * FROM tabela1")
d1 <- dbFetch(rs)
    
13.12.2018 / 21:12