Skip to contents

Connects to a MySQL or MariaDB database, executes a SQL query, and returns the result as a tidylearn_data object. Accepts either a connection string or individual connection parameters. Requires DBI and RMariaDB.

Usage

tl_read_mysql(
  dsn,
  query,
  dbname = NULL,
  user = NULL,
  password = NULL,
  port = 3306,
  ...
)

Arguments

dsn

A MySQL connection string (e.g., "mysql://user:pass@host:port/dbname"), or the database host if using named parameters. Percent-encode special characters in the user name and password (@ as %40). Query parameters are refused, because RMariaDB ignores arguments it does not know; pass its dbConnect() arguments, such as ssl.ca, through ....

query

A SQL query string.

dbname

Database name (if not in dsn).

user

Username (if not in dsn).

password

Password (if not in dsn), which keeps it out of the connection string.

port

Port number (if not in dsn). Default is 3306.

...

Additional arguments passed to DBI::dbConnect().

Value

A tidylearn_data object containing the query results.

Examples

if (FALSE) { # \dontrun{
# Needs a running MySQL or MariaDB server
tl_read_mysql(
  dsn = "localhost",
  query = "SELECT * FROM my_table",
  dbname = "mydb",
  user = "myuser",
  password = Sys.getenv("MYSQL_PWD")
)
} # }