Tutorial
Data-Powered AI: Connect OpenClaw to your databases for intelligent querying, reporting, and automation without writing SQL.
Why Integrate Databases with OpenClaw?
Connecting OpenClaw to your databases enables:
- Natural language queries: Ask questions in plain English
- Automated reporting: Generate reports on schedule
- Data monitoring: Get alerted to anomalies
- Chat-powered analytics: Explore data conversationally
Supported Databases
OpenClaw supports integration with:
- SQL: PostgreSQL, MySQL, SQLite, SQL Server
- NoSQL: MongoDB, Redis, Cassandra
- Cloud: Supabase, PlanetScale, Firestore
Setting Up Database Connections
PostgreSQL Example
openclaw config set database.type="postgresql"
openclaw config set database.host="localhost"
openclaw config set database.port=5432
openclaw config set database.name="mydb"
openclaw config set database.user="openclaw"
openclaw config set database.password="${DB_PASSWORD}"
MongoDB Example
openclaw config set database.type="mongodb"
openclaw config set database.uri="mongodb://localhost:27017/mydb"
Natural Language Queries
Ask Questions in Plain English
"How many users signed up this week?"
OpenClaw translates this to:
SELECT COUNT(*) FROM users WHERE created_at >= NOW() - INTERVAL '7 days'
Complex Queries
"Show me the top 10 products by revenue in January, grouped by category"
Building Database Skills
Custom Query Skills
Create skills for common database operations:
// skills/database-summary.ts
export async function generateDatabaseSummary() {
const stats = await db.query(`
SELECT
(SELECT COUNT(*) FROM users) as total_users,
(SELECT COUNT(*) FROM orders) as total_orders,
(SELECT SUM(amount) FROM orders) as total_revenue
`);
return formatSummary(stats);
}
Automated Reporting
Scheduled Reports
openclaw cron create "db:daily-report" \
--schedule "0 9 * * *" \
--message "Generate daily sales report and send to #sales channel"
Security Best Practices
- Use read-only users for reporting queries
- Limit schema access to necessary tables only
- Avoid exposing credentials in chat messages
- Audit query logs regularly
- Use connection pooling for production deployments
Advanced: Multi-Database Queries
OpenClaw can query across multiple databases:
"Compare user counts between the production and staging databases"
Troubleshooting
Connection Issues
- Verify database is accessible from OpenClaw host
- Check firewall rules allow database port
- Confirm credentials are correct
Query Errors
- Check database logs for failed queries
- Verify table and column names exist
- Review permissions for database user