> ## 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 Agent 存储

Agno 支持使用 `MySQLStorage` 类将 MySQL 作为 Agents 的存储后端。

## 用法

### 运行 MySQL

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

```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 mysql_storage_for_agent.py theme={null}
from agno.storage.mysql import MySQLStorage

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

# 使用 Postgres 数据库创建存储后端
storage = MySQLStorage(
    # 将 sessions 存储在 agno.sessions 表中
    table_name="agent_sessions",
    # db_url: MySQL 数据库 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)
