> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL 存储

Agno 支持使用 MySQL 作为代理的存储后端，通过 `MySQLStorage` 类。

## 用法

### 运行 MySQL

安装 [Docker Desktop](https://docs.docker.com/desktop/install/mac-install/) 并使用以下命令在 **3306** 端口运行 **MySQL**：

```bash theme={null}
docker run -d \
  -e MYSQL_ROOT_PASSWORD=root \
  -e MYSQL_DATABASE=agno \
  -e MYSQL_USER=agno \
  -e MYSQL_PASSWORD=agno \
  -p 3306:3306 \
  --name mysql \
  mysql:8.0
```

```python postgres_storage_for_agent.py theme={null}
from agno.storage.mysql import MySQLStorage

db_url = "mysql+pymysql://agno:agno@localhost:3306/agno"

# 使用 Postgres 数据库创建存储后端
storage = MySQLStorage(
    # 将会话存储在 agno.sessions 表中
    table_name="agent_sessions",
    # db_url: Postgres 数据库的 URL
    db_url=db_url,
)

# 将存储添加到 Agent
agent = Agent(storage=storage)
```

## 参数

<Snippet file="storage-mysql-params.mdx" />

## 开发资源

* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/storage/mysql_storage/mysql_storage_for_agent.py)
