Skip to main content
Agno supports using MySQL asynchronously, with the AsyncMySQLDb class.

Usage

async_mysql_for_agent.py
from agno.agent import Agent
from agno.db.postgres import AsyncPostgresDb

# Replace with your own connection string, and notice the `async_` prefix
db_url = "postgresql+psycopg_async://ai:ai@localhost:5532/ai"

# Setup your Database
db = AsyncPostgresDb(db_url=db_url)

# Setup your Agent with the Database
agent = Agent(db=db)

Run MySQL

Install docker desktop and run MySQL on port 3306 using:
docker run -d \
  --name mysql \
  -e MYSQL_ROOT_PASSWORD=ai \
  -e MYSQL_DATABASE=ai \
  -e MYSQL_USER=ai \
  -e MYSQL_PASSWORD=ai \
  -p 3306:3306 \
  -d mysql:8

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_urlOptional[str]-The database URL to connect to.
db_engineOptional[AsyncEngine]-The SQLAlchemy asyncdatabase engine to use.
db_schemaOptional[str]-The database schema to use.
session_tableOptional[str]-Name of the table to store Agent, Team and Workflow sessions.
memory_tableOptional[str]-Name of the table to store memories.
metrics_tableOptional[str]-Name of the table to store metrics.
eval_tableOptional[str]-Name of the table to store evaluation runs data.
knowledge_tableOptional[str]-Name of the table to store knowledge content.
traces_tableOptional[str]-Name of the table to store traces.
spans_tableOptional[str]-Name of the table to store spans.

Developer Resources