Skip to content

MySQL guide

The MySQL ADBC driver is distributed via the ADBC Driver Foundry, not PyPI. Follow the Foundry installation guide to install it before using MySQLConfig.

adbc-poolhouse does not need a separate extra for MySQL:

pip install adbc-poolhouse

Connection

MySQLConfig connects to a MySQL server. You must specify the connection in one of two ways: a full URI or individual fields (host and user together, with optional password, database, and port).

Construction raises ConfigurationError if neither mode is fully specified.

URI mode

from pydantic import SecretStr

from adbc_poolhouse import MySQLConfig, create_pool

config = MySQLConfig(
    uri=SecretStr("root:password@tcp(localhost:3306)/mydb"),  # pragma: allowlist secret
)
pool = create_pool(config)

Individual fields

from adbc_poolhouse import MySQLConfig, create_pool

config = MySQLConfig(
    host="localhost",
    user="root",
    password="password",  # pragma: allowlist secret
    database="mydb",
)
pool = create_pool(config)

password is optional — MySQL supports passwordless connections. port defaults to 3306.

Loading from environment variables

MySQLConfig reads all fields from environment variables with the MYSQL_ prefix:

export MYSQL_HOST=localhost
export MYSQL_USER=root
export MYSQL_PASSWORD=password  # pragma: allowlist secret
export MYSQL_DATABASE=mydb
config = MySQLConfig()  # reads from env
pool = create_pool(config)

See also