mem0ai/mem0 · error · ImportError

Azure MySQL vector store requires PyMySQL and DBUtils. Pleas

Error message

Azure MySQL vector store requires PyMySQL and DBUtils. Please install them using 'pip install pymysql dbutils'

What it means

Raised at module import of mem0.vector_stores.azure_mysql when pymysql or dbutils (DBUtils' PooledDB) cannot be imported. The Azure MySQL store needs PyMySQL for the wire protocol and DBUtils for connection pooling; both are optional dependencies. Note that azure.identity failing to import is tolerated separately — only the pymysql/dbutils pair is fatal.

Source

Thrown at mem0/vector_stores/azure_mysql.py:14

import json
import logging
import re
from contextlib import contextmanager
from typing import Any, Dict, List, Optional

from pydantic import BaseModel

try:
    import pymysql
    from dbutils.pooled_db import PooledDB
    from pymysql.cursors import DictCursor
except ImportError:
    raise ImportError(
        "Azure MySQL vector store requires PyMySQL and DBUtils. "
        "Please install them using 'pip install pymysql dbutils'"
    )

try:
    from azure.identity import DefaultAzureCredential
    AZURE_IDENTITY_AVAILABLE = True
except ImportError:
    AZURE_IDENTITY_AVAILABLE = False

from mem0.vector_stores.base import VectorStoreBase

logger = logging.getLogger(__name__)

_SAFE_IDENTIFIER_RE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]{0,127}$')


def _validate_identifier(name: str, label: str = "identifier") -> str:

View on GitHub (pinned to 001c235229)

Solutions

  1. pip install pymysql dbutils
  2. Add both to requirements.txt / rebuild the Docker image
  3. Verify: python -c "import pymysql; from dbutils.pooled_db import PooledDB"
  4. Ensure the install lands in the same interpreter/venv your app runs under

Example fix

# before: ImportError: Azure MySQL vector store requires PyMySQL and DBUtils ...
from mem0 import Memory
m = Memory.from_config(azure_mysql_cfg)

# after
# pip install pymysql dbutils
from mem0 import Memory
m = Memory.from_config(azure_mysql_cfg)
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util
missing = [m for m in ('pymysql', 'dbutils') if importlib.util.find_spec(m) is None]
if missing:
    raise ConfigError(f'azure_mysql requires: {missing} — pip install pymysql dbutils')

Try / catch

try:
    from mem0.vector_stores.azure_mysql import AzureMySQL
except ImportError as e:
    if 'PyMySQL and DBUtils' in str(e):
        raise ConfigError('pip install pymysql dbutils') from e
    raise

Prevention

When it happens

Trigger: Configuring vector_store.provider='azure_mysql' in an environment missing pymysql or dbutils; having PyMySQL but not DBUtils (they are separate packages); a slim Docker image built from core mem0ai requirements only.

Common situations: pip install mem0ai then selecting Azure MySQL; DBUtils package name confusion (pip package is 'dbutils', import is 'dbutils.pooled_db'); venv mismatch between install and run.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/33a0a6cb15e01295. Report an issue: GitHub.