crewAIInc/crewAI · error · ValueError
Database name is required in the URI
Error message
Database name is required in the URI
What it means
Raised by MySQLLoader.load() when the db_uri parses but contains no database name — parsed.path is empty or only slashes, so database becomes None/empty after lstrip('/'). The loader requires the schema to be part of the URI because pymysql connects to a specific database and the code never issues USE.
Source
Thrown at lib/crewai-tools/src/crewai_tools/rag/loaders/mysql_loader.py:49
query = source.source
parsed = urlparse(db_uri)
if parsed.scheme not in ["mysql", "mysql+pymysql"]:
raise ValueError(f"Invalid MySQL URI scheme: {parsed.scheme}")
connection_params = {
"host": parsed.hostname or "localhost",
"port": parsed.port or 3306,
"user": parsed.username,
"password": parsed.password,
"database": parsed.path.lstrip("/") if parsed.path else None,
"charset": "utf8mb4",
"cursorclass": DictCursor,
}
if not connection_params["database"]:
raise ValueError("Database name is required in the URI")
try:
connection = connect(**connection_params)
try:
with connection.cursor() as cursor:
cursor.execute(query)
rows = cursor.fetchall()
if not rows:
content = "No data found in the table"
return LoaderResult(
content=content,
metadata={"source": query, "row_count": 0},
doc_id=self.generate_doc_id(
source_ref=query, content=content
),
)
View on GitHub (pinned to 754d7323be)
Solutions
- Append the database name to the URI: mysql://user:pass@host:3306/mydatabase.
- Build the URI from parts with a check that db is non-empty before composing the string.
- If the database name contains special characters, URL-encode it so the path still parses.
Example fix
# before
result = MySQLLoader().load(src, metadata={'db_uri': 'mysql://u:p@h:3306'})
# after
result = MySQLLoader().load(src, metadata={'db_uri': 'mysql://u:p@h:3306/app_db'}) Defensive patterns
Strategy: validation
Validate before calling
from urllib.parse import urlparse\n\ndef uri_has_database(uri: str) -> bool:\n return bool(urlparse(uri).path.lstrip('/')) Prevention
- Always compose URIs with an explicit /dbname.
- Validate the path segment when building URIs from parts.
- URL-encode database names with special characters.
When it happens
Trigger: Passing 'mysql://user:pass@host:3306' (no /dbname); 'mysql://user:pass@host:3306/' (trailing slash only); URIs where the path segment was lost during templating or URL-encoding.
Common situations: Storing server coordinates in config and expecting the loader to take the database from a separate key; templating bugs that render an empty database placeholder (mysql://u:p@h:3306/); copy-paste from connection strings used by GUI clients that keep the database in a separate field.
Related errors
- Database URI is required for MySQL loader
- Invalid MySQL URI scheme: {parsed.scheme}
- Project name cannot be empty
- Project name '{name}' produces invalid folder name '{folder_
- No deployable project files were found.
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/cc74c384653fe650.
Report an issue: GitHub.