crewAIInc/crewAI · error · ValueError
Failed to load data from MySQL: {e}
Error message
Failed to load data from MySQL: {e} What it means
Raised by MySQLLoader.load() for any non-pymysql exception during loading — the catch-all `except Exception` after the `except Error` clause. It typically fires before the DB is even reached: most commonly ModuleNotFoundError/ImportError because the module imports `connect`/`DictCursor`/`Error` from pymysql at import time in environments where pymysql is not installed, plus errors like URL parsing edge cases or dict/key errors while building connection params.
Source
Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/mysql_loader.py:102
if len(content) > 100000:
content = content[:100000] + "\n\n[Content truncated...]"
return LoaderResult(
content=content,
metadata={
"source": query,
"database": connection_params["database"],
"row_count": len(rows),
"columns": columns,
},
doc_id=self.generate_doc_id(source_ref=query, content=content),
)
finally:
connection.close()
except Error as e:
raise ValueError(f"MySQL database error: {e}") from e
except Exception as e:
raise ValueError(f"Failed to load data from MySQL: {e}") from e
View on GitHub (pinned to 754d7323be)
Solutions
- Install the driver: pip install pymysql (or `pip install crewai-tools[rag]` / `uv add pymysql`).
- Read the chained cause ({e}) — if it is ModuleNotFoundError the fix is the install above; otherwise address the specific underlying error.
- Pin and sync the environment (uv sync / pip install -r) so pymysql survives rebuilds.
Example fix
# before
result = MySQLLoader().load(SourceContent('SELECT 1'), metadata={'db_uri': uri}) # ModuleNotFoundError wrapped
# after
# terminal: pip install pymysql
result = MySQLLoader().load(SourceContent('SELECT 1'), metadata={'db_uri': uri}) Defensive patterns
Strategy: validation
Validate before calling
import importlib.util\n\ndef pymysql_available() -> bool:\n return importlib.util.find_spec('pymysql') is not None Try / catch
try:\n result = MySQLLoader().load(src, metadata={'db_uri': uri})\nexcept ValueError as e:\n if 'Failed to load data from MySQL' in str(e) and not pymysql_available():\n raise RuntimeError('install pymysql: pip install pymysql') from e\n raise Prevention
- Install pymysql wherever MySQLLoader may run.
- Add a dependency capability check at service startup.
- Read the chained cause message — this wrapper hides the real error class.
When it happens
Trigger: Importing/running MySQLLoader in an environment where pymysql is not installed (crewai-tools without the rag/DB extra); any unexpected exception while assembling parameters or formatting results that is not a pymysql.Error.
Common situations: Slim Docker/CI images without the optional database extras; assuming the loader uses SQLAlchemy (already installed) when it actually requires pymysql; environments where the dependency was pruned by a lockfile.
Related errors
- Database URI is required for MySQL loader
- Invalid MySQL URI scheme: {parsed.scheme}
- Database name is required in the URI
- MySQL database error: {e}
- Project name cannot be empty
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/d97176f49e15dbaa.
Report an issue: GitHub.