crewAIInc/crewAI · error · ValueError
MySQL database error: {e}
Error message
MySQL database error: {e} What it means
Raised by MySQLLoader.load() when the database interaction raises pymysql.Error — the except Error clause catches connection failures (bad credentials ER_ACCESS_DENIED, unknown host, unreachable server, unknown table/column in the executed query) raised by connect() or cursor.execute(query). The original MySQL error number/message is included and chained.
Source
Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/mysql_loader.py:100
content = "\n".join(text_parts)
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
- Test the same URI and query with a plain client: mysql --host=... -u ... -p -e 'SELECT 1' to isolate credentials vs network vs query errors.
- Fix credentials/host in the db_uri; ensure the DB server accepts connections from where the loader runs.
- Run the exact query manually against the URI's database to catch SQL typos before ingestion.
- Upgrade pymysql if you see authentication plugin errors against MySQL 8.
Example fix
# before
result = MySQLLoader().load(SourceContent('SELECT * FROM usr'), metadata={'db_uri': uri}) # 1146
# after
result = MySQLLoader().load(SourceContent('SELECT * FROM users'), metadata={'db_uri': uri}) Defensive patterns
Strategy: try-catch
Validate before calling
import pymysql\n\ndef can_connect(uri_check: dict) -> bool:\n try:\n pymysql.connect(**uri_check, connect_timeout=5)\n return True\n except pymysql.Error:\n return False
Try / catch
try:\n result = MySQLLoader().load(src, metadata={'db_uri': uri})\nexcept ValueError as e:\n if 'MySQL database error' in str(e):\n classify_and_alert(str(e)) # credentials vs network vs SQL syntax\n raise Prevention
- Smoke-test connectivity and the exact SQL before batch ingestion.
- Pull credentials from a secrets manager with rotation awareness.
- Restrict queries to known-good table names, not free user text.
When it happens
Trigger: Wrong username/password (1045 Access denied); MySQL server down or host/port blocked by firewall (2003 Can't connect); executing a query with a typo'd table or column (1146/1054); querying a table in a different schema than the URI's database; packet or auth plugin incompatibilities (caching_sha2_password with old clients).
Common situations: Rotated DB credentials not propagated to the agent config; network policies blocking the DB port from containerized runs; query strings built from user input with table names that don't exist; MySQL 8 auth plugin issues with outdated pymysql; dev/prod schema drift.
Related errors
- Database URI is required for MySQL loader
- Invalid MySQL URI scheme: {parsed.scheme}
- Database name is required in the URI
- Failed to load data from MySQL: {e}
- PostgreSQL database error: {e}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/8fd5abf5c53735cc.
Report an issue: GitHub.