Rmysql - My querys return a list

Asked

Viewed 50 times

0

Hi, I’m working with a database that I usually access with Workbench. To start importing directly into R, I am using the Rmysql library. I can make the connection and find my tables, but when it comes to importing with tbl it returns me a list. How can I make it return me a df (Tabela1 object 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 command dbReadTable , 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 your help!

2 answers

0

I 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")
  • I tried to connect with this package but it returns me another weird error: "Error in (Function (classes, fdef, mtable) : Unable to find an inherited method for Function ?dbConnect' for Signature"Missing"

  • I think I gave the package wrong. This is a specific one for the server that we use. The package that is most Generico is odbc instead of Rmysql.

0

I managed 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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.