dataTamer logodataTamer
Back to Tutorials
Beginner15 min read

Connecting a SQL Database

Connect MySQL or PostgreSQL databases and query your data using AI-powered chat.

What You'll Learn

How to connect MySQL and PostgreSQL databases
Best practices for secure database connections
Testing your database connection
Querying databases with natural language
Understanding database indexing and optimization
1

Prepare Your Database Credentials

Gather the following information from your database administrator:

  • Host: The database server address (e.g., db.example.com)
  • Port: Usually 3306 for MySQL or 5432 for PostgreSQL
  • Database Name: The specific database you want to connect
  • Username & Password: Your database credentials
2

Create a Read-Only User (Recommended)

For enhanced security, create a dedicated read-only user for dataTamer.

⚠️ Security: Never use admin credentials. Create a read-only user to minimize security risks.

For PostgreSQL:

CREATE USER datatamer_readonly WITH PASSWORD 'your_password';
GRANT CONNECT ON DATABASE your_database TO datatamer_readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO datatamer_readonly;

For MySQL:

CREATE USER 'datatamer_readonly'@'%' IDENTIFIED BY 'your_password';
GRANT SELECT ON your_database.* TO 'datatamer_readonly'@'%';
FLUSH PRIVILEGES;
3

Add Database Datasource

  1. 1. Navigate to Datasources in the left sidebar
  2. 2. Click "Add Datasource"
  3. 3. Select "SQL Database" (MySQL or PostgreSQL)
  4. 4. Click "Continue"
4

Enter Connection Details

Fill in the database connection form:

  • Database Type: Select MySQL/MariaDB or PostgreSQL
  • Host: Enter your database server address
  • Port: Enter the port (default: 3306 or 5432)
  • Database, Username, Password: Enter your credentials
  • SSL/TLS: Enable if your database requires secure connections

💡 Connection String: You can also provide a full connection URL like postgresql://user:password@host:port/database

5

Test the Connection

  1. 1. Click the "Test Connection" button
  2. 2. dataTamer will attempt to connect to your database
  3. 3. If successful, you'll see a green checkmark and list of tables
  4. 4. If it fails, review the error message and check your credentials

✓ Success! Connection established. You can now select which tables to index.

6

Configure Data Extraction

Choose which tables and data to make searchable:

  • Select Tables: Choose specific tables or select all
  • Row Limit: Optionally limit rows for testing
  • Refresh Schedule: Set how often to sync with your database
7

Query Your Database with AI

Once indexing is complete, ask natural language questions like:

  • "Show me all customers who signed up last month"
  • "What's the total revenue by product category?"
  • "Find orders with 'pending' status for more than 7 days"

💡 Pro Tip: The AI can automatically join related tables and perform complex aggregations.

Next Steps

Excellent! You've connected a SQL database to dataTamer. Ready to explore more datasources?