No database selected with RMySQL
Asked Answered
P

2

7

I'm trying to connect to remote publicly-accessible MySQL server EnsEMBL public server using RMySQL, but when I try to list the tables, an error occurs:

library(RMySQL)

mydb = dbConnect(MySQL(), 
                 user = 'anonymous',
                 port = 5306,
                 host = 'asiadb.ensembl.org')

dbListTables(mydb)

Error in .local(conn, statement, ...) : 
  could not run statement: No database selected

Is there a a way to find out the name? Or Am I making a completely different mistake altogether?

Portuna answered 9/1, 2016 at 20:15 Comment(0)
W
13

You have to specify the name of the db in the dbConnect call. e.g. :

mydb = dbConnect(MySQL(), 
                 user = 'anonymous',
                 port = 5306,
                 host = 'asiadb.ensembl.org',
                 db = 'homo_sapiens_core_83_38')

dbListTables(mydb)
Wulf answered 9/1, 2016 at 20:24 Comment(3)
Thanks! Is there a way to find out the names? Do I have to find this out somewhere on their web, or can I get that information by a query from R?Portuna
names of folders on this page ftp.ensembl.org/pub/release-83/mysql seems to be also names of various dbWulf
Ok, so I have to know the db name beforehand. Thanks for this!Portuna
Z
2

It is weird that database = 'testdb' executed with dbExecute in R

db <- dbConnect(RMySQL::MySQL(), 
        user = 'root',
        password = 'pwd123',
        host = 'localhost',
        database = 'testdb'
      )
dbExecute(db, MySQLStatement) # Executed Without Error

But when used dbListTables(db) showing no databases selected.

Changed database into db worked as expected

db <- dbConnect(RMySQL::MySQL(), 
        user = 'root',
        password = 'pwd123',
        host = 'localhost',
        db = 'testdb'
      )
Zirconium answered 3/1, 2021 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.