Skip to content

MySQL

Installation

pip install "toolfront[mysql]"

Connection URL

Connect to MySQL by passing a connection URL to the Database constructor:

1
2
3
4
5
from toolfront import Database

db = Database(url="mysql://{user}:{password}@{host}:{port}/{database}")

revenue = db.ask("What's our total revenue this month?")

Connection Parameters

Alternatively, connect using the Database.from_mysql() method with parameters:

from toolfront import Database

db = Database.from_mysql(
    host="localhost",
    port=3306,
    database="sales",
    user="user",
    password="pass"
)

revenue = db.ask("What's our total revenue this month?")
PARAMETER DESCRIPTION
host

Hostname. Default is 'localhost'.

TYPE: str DEFAULT: 'localhost'

user

Username.

TYPE: str DEFAULT: None

password

Password.

TYPE: str DEFAULT: None

port

Port. Default is 3306.

TYPE: int DEFAULT: 3306

database

Database name.

TYPE: str DEFAULT: None

autocommit

Autocommit mode. Default is True.

TYPE: bool DEFAULT: True

match_schema

Regex pattern to filter schemas. Mutually exclusive with match_tables.

TYPE: str DEFAULT: None

match_tables

Regex pattern to filter tables. Mutually exclusive with match_schema.

TYPE: str DEFAULT: None

**kwargs

Additional keyword arguments passed to MySQLdb.connect.

TYPE: Any DEFAULT: {}