List the database tables
After you've successfully connected to a remote MySQL database, the next step is to see what tables the database contains. You can do this with the dbListTables()
function. As you might remember from the video, this function requires the connection object as an input, and outputs a character vector with the table names.
This is a part of the course
“Intermediate Importing Data in R”
Exercise instructions
- Add code to create a vector
tables
, that contains the tables in the tweater database. You can connect to this database through thecon
object. - Display the structure of
tables
; what's the class of this vector?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the DBI package
library(DBI)
# Connect to the MySQL database: con
con <- dbConnect(RMySQL::MySQL(),
dbname = "tweater",
host = "courses.csrrinzqubik.us-east-1.rds.amazonaws.com",
port = 3306,
user = "student",
password = "datacamp")
# Build a vector of table names: tables
# Display structure of tables
This exercise is part of the course
Intermediate Importing Data in R
Parse data in any format. Whether it's flat files, statistical software, databases, or data right from the web.
Many companies store their information in relational databases. The R community has also developed R packages to get data from these architectures. You'll learn how to connect to a database and how to retrieve data from it.
Exercise 1: Connect to a databaseExercise 2: Establish a connectionExercise 3: Inspect the connectionExercise 4: Import table dataExercise 5: List the database tablesExercise 6: Import usersExercise 7: Import all tablesExercise 8: How do the tables relate?What is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.