cookbook/06_storage/mysql/README.md
Examples demonstrating MySQL database integration with Agno agents, teams, and workflows.
uv pip install mysql-connector-python sqlalchemy pymysql
uv pip install sqlalchemy asyncmy
from agno.agent import Agent
from agno.db.mysql import MySQLDb
db = MySQLDb(db_url="mysql+pymysql://username:password@localhost:3306/database")
agent = Agent(
db=db,
add_history_to_context=True,
)
import asyncio
from agno.agent import Agent
from agno.db.mysql import AsyncMySQLDb
db = AsyncMySQLDb(db_url="mysql+asyncmy://username:password@localhost:3306/database")
agent = Agent(
db=db,
add_history_to_context=True,
)
asyncio.run(agent.aprint_response("Hello!"))
mysql_for_agent.py - Agent with MySQL storagemysql_for_team.py - Team with MySQL storageasync_mysql/async_mysql_for_agent.py - Agent with Async MySQL storageasync_mysql/async_mysql_for_team.py - Team with Async MySQL storageasync_mysql/async_mysql_for_workflow.py - Workflow with Async MySQL storagemysql+pymysql://user:password@host:port/databasemysql+mysqlconnector://user:password@host:port/databasemysql+asyncmy://user:password@host:port/databaseChoose AsyncMySQLDb when:
Choose MySQLDb when: