MySQL Integration Guide

MySQL Integration Guide

Complete guide for connecting MySQL databases to Tellus

Guide Contents

  1. Overview
  2. Getting Started
  3. Obtaining Credentials
  4. Configuration
  5. Tellus Integration
  6. Basic Operations (CRUD)
  7. Using MySQL
  8. Example Setup
  9. Data Types
  10. Security

Overview

MySQL is a popular open-source relational database management system (RDBMS). It's widely used for web applications and known for reliability and performance.

Integration Type: Relational Database (RDBMS)
Authentication: Username and password
Connection Method: TCP/IP with MySQL wire protocol
Default Port: 3306

Getting Started

Prerequisites:

Options for Getting MySQL:

Steps for Cloud (Example: DigitalOcean):

  1. Sign up for DigitalOcean account
  2. Navigate to "Databases"
  3. Click "Create Database Cluster"
  4. Select MySQL
  5. Choose version 8.0 or 8.1
  6. Select region and cluster size
  7. Click "Create Database"
  8. Wait for initialization (5-10 minutes)

Obtaining Credentials

Required Credentials:

A) MySQL Host
Cloud service examples: xxxxx-mysql-do-user-xxxxx.c.db.ondigitalocean.com
Local machine: localhost or 127.0.0.1

B) MySQL Port
Default: 3306
Cloud services may use custom ports

C) MySQL Username
Cloud: Usually shown in connection details
Local: You created this (e.g., "root" or "appuser")

D) MySQL Password
Cloud: Set during user creation or reset in console
Local: Set when creating the user

E) MySQL Database
Optional default database to connect to
Examples: "appdb", "production", "myapp_test"

Example Connection:
Host: localhost
Port: 3306
Username: appuser
Password: strongPassword123!
Database: appdb

Configuration in Dashboard

  1. Click "Add Project"
  2. Select "MySQL" as Database Provider
  3. Fill in MySQL Credentials:
    • MySQL Host: Your database server address
    • MySQL Port: Database port (usually 3306)
    • MySQL Username: Your database username
    • MySQL Password: Your database password
    • MySQL Database: (Optional) Default database name
  4. Click "Test Connection" to verify credentials
  5. Click "Save Project"

Common Connection Issues:
❌ "Connection refused": Verify host address and port
❌ "Access denied": Check username and password
❌ "Cannot reach host": Check firewall rules allow connection

Tellus Integration

Tellus provides a modern, ORM-like experience on top of your standard MySQL relational databases without sacrificing raw SQL capabilities. Configure your connection in tellus.config.js:

import { Tellus } from '@tellus/client';

const tellus = new Tellus({
  databases: {
    production: {
      provider: 'mysql',
      host: process.env.MYSQL_HOST,
      port: 3306,
      user: process.env.MYSQL_USER,
      password: process.env.MYSQL_PASSWORD,
      database: 'main_db'
    }
  }
});

Basic Operations (CRUD)

Write type-safe queries without building raw SQL strings.

1. Create (Insert)

// Insert a new user, automatically mapping to MySQL columns
const newUser = await tellus.db('production').collection('users').insert({
  email: 'hello@tellus.dev',
  first_name: 'John',
  last_name: 'Doe'
});

2. Read (Select)

// Perform a query with Tellus's unified relational operators
const recentUsers = await tellus.db('production').collection('users')
  .where('created_at', '>=', new Date(Date.now() - 86400000))
  .orderBy('created_at', 'desc')
  .limit(10)
  .execute();

3. Update

// Update user records safely
await tellus.db('production').collection('users')
  .where('id', '==', newUser.id)
  .update({ last_name: 'Smith' });

4. Delete

// Remove a user
await tellus.db('production').collection('users')
  .where('id', '==', newUser.id)
  .delete();

Using MySQL in the Dashboard

Example Setup: E-commerce Database

Create tables:

CREATE TABLE customers (
  id INT PRIMARY KEY AUTO_INCREMENT,
  email VARCHAR(100) NOT NULL UNIQUE,
  first_name VARCHAR(50) NOT NULL,
  last_name VARCHAR(50) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE products (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  price DECIMAL(10, 2) NOT NULL,
  stock_quantity INT DEFAULT 0,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE orders (
  id INT PRIMARY KEY AUTO_INCREMENT,
  customer_id INT NOT NULL,
  total_amount DECIMAL(10, 2) NOT NULL,
  status VARCHAR(20) DEFAULT 'pending',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (customer_id) REFERENCES customers(id)
);

Create indexes for performance:

CREATE INDEX idx_customers_email ON customers(email);
CREATE INDEX idx_products_stock ON products(stock_quantity);
CREATE INDEX idx_orders_customer ON orders(customer_id);
CREATE INDEX idx_orders_status ON orders(status);

MySQL Data Types

Numeric:

String:

Date/Time:

Other:

Security Best Practices

Useful Links

← MongoDBAll Guides