MySQL Persistence
SQL database persistence with connection pooling and auto schema creation
MySQL persists agent conversations with automatic schema creation and connection pooling.
from praisonaiagents import Agent, MemoryConfig
from praisonaiagents import db
agent = Agent(
name="MySQLBot",
instructions="You are a helpful assistant.",
memory=MemoryConfig(
db=db(database_url="mysql://user:pass@localhost:3306/praisonai"),
session_id="mysql-session",
))
agent.start("Hello — save this to MySQL")The user resumes a session; MySQL persists the full conversation history.
Quick Start
- Simple Usage
bash pip install mysql-connector-python praisonaipython from praisonaiagents import Agent, MemoryConfig from praisonaiagents import db agent = Agent( name="MySQLBot", memory=MemoryConfig( db=db(database_url="mysql://user:pass@localhost:3306/praisonai"), session_id="session-1", )) agent.start("Hello!") - With Configuration
python from praisonai.persistence.conversation.mysql import MySQLConversationStore store = MySQLConversationStore( host="localhost", port=3306, database="praisonai", user="root", password="secret", table_prefix="praison_", auto_create_tables=True, pool_size=10, )
How It Works
| Table | Purpose |
|---|---|
praison_sessions | Session metadata |
praison_messages | Conversation history |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
url | str | None | Full MySQL URL (overrides individual options) |
host | str | "localhost" | MySQL server hostname |
port | int | 3306 | MySQL server port |
database | str | "praisonai" | Database name |
user | str | "root" | Database username |
password | str | "" | Database password |
table_prefix | str | "praison_" | Prefix for table names |
auto_create_tables | bool | True | Create tables automatically |
pool_size | int | 5 | Connection pool size |
URL formats
db(database_url="mysql://user:pass@localhost:3306/praisonai")
db(database_url="mysql://user:pass@host:3306/db?charset=utf8mb4")For async workloads, use create_conversation_store("async_mysql", ...).
Best Practices
Use db() for most agents
Agent( memory=MemoryConfig( db=db(database_url="mysql://..."), )) handles store wiring — no manual setup needed.
Set table_prefix for multi-tenancy
Isolate apps on one database with different prefixes: table_prefix="prod_" vs table_prefix="staging_".
Tune pool_size for concurrency
Increase pool_size for high-traffic deployments; use smaller pools for serverless MySQL hosts.
Use SSL in production
Append ?ssl_mode=REQUIRED to the connection URL for encrypted connections.