MySQL guide¶
Installation¶
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:
Connection¶
MySQLConfig connects to a MySQL server. You must specify the connection in one of two
ways: a full URI or individual fields (host, user, and database together, with optional
password and port).
Construction raises ConfigurationError (wrapped as a Pydantic ValidationError) 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, since MySQL supports passwordless connections. port defaults to 3306. database is not optional in this mode: omitting it fails validation, the same as omitting host or user.
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
See also¶
- Configuration — env_prefix, pool tuning
- Pool lifecycle — close_pool, pytest fixtures