Back to Articles
RAG

How to Connect PostgreSQL, MySQL, & MongoDB to a Custom AI Chatbot

Dr. Aaron Vance
Dr. Aaron Vance
Head of AI Research
July 28, 2026 6 min read

Why Static Files Aren't Enough for Live Data

Static documents like PDFs or static web pages are great for policies, but they fall short when answering dynamic operational questions like "How many active subscribers do we have today?" or "What is the latest stock level for item X?".

Connecting your database directly to your AI chatbot allows the assistant to query live production data without requiring manual document re-indexing.

Step-by-Step Connection Guide

Step 1: Choose Your Database Engine

In Aidni.io, open your Chatbot Dashboard, navigate to the Data Sources tab, and click Connect Database. Select your engine:

  • PostgreSQL (Port 5432 - Supabase, Neon, AWS RDS)
  • MySQL (Port 3306 - PlanetScale, MariaDB, Localhost)
  • MongoDB (Port 27017 - MongoDB Atlas, DocumentDB)

Step 2: Enter Your Connection String

Paste your standard connection URI string. Aidni.io automatically encrypts all connection strings using server-side AES-256-GCM encryption and masks sensitive passwords in the UI (e.g., postgresql://user:••••••••@host:5432/dbname).

Step 3: Select Synchronization Mode

  • ⚡ Live Lookups (Real-Time Dynamic Mode): Queries table records dynamically when website visitors ask questions.
  • 📦 Table Vectorization (Static RAG Mode): Indexes table rows into vector embeddings for similarity search.

Step 4: Test & Auto-Discover Schema

Click Test Connection. Aidni.io runs schema auto-discovery, extracting table names and column structures so the AI query router understands your data schema automatically.

Security & Read-Only Recommendations

Always use a read-only database user when connecting any third-party tool. In PostgreSQL, you can create a read-only user with two simple commands:

CREATE USER aidni_reader WITH PASSWORD 'secure_password';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO aidni_reader;

Conclusion

Connecting your production database transforms your AI chatbot from a simple FAQ bot into a real-time conversational business intelligence agent.