Guide Contents
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:
- Access to a MySQL server (cloud-hosted or local)
- Database user credentials
- Network access to the MySQL server
Options for Getting MySQL:
- Cloud-Hosted (Recommended): Amazon RDS, Google Cloud SQL, DigitalOcean Managed Databases, etc.
- Self-Hosted Local: Download and install MySQL on your machine
- Docker: Run MySQL in a container for development
Steps for Cloud (Example: DigitalOcean):
- Sign up for DigitalOcean account
- Navigate to "Databases"
- Click "Create Database Cluster"
- Select MySQL
- Choose version 8.0 or 8.1
- Select region and cluster size
- Click "Create Database"
- 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
- Click "Add Project"
- Select "MySQL" as Database Provider
- 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
- Click "Test Connection" to verify credentials
- 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
- Browse Database Structure - View databases, tables, columns, and constraints
- View Table Data - Click any table to see records
- Search and Filter Data - Filter by column values and sort
- Execute SQL Queries - Run custom SELECT queries
- Add Records - Insert new rows into tables
- Edit Records - Modify cell values
- Delete Records - Remove unwanted data
- View Schema Details - Check column types, constraints, indexes
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:
- INT: Integer numbers (-2^31 to 2^31-1)
- BIGINT: Large integers
- DECIMAL(10,2): Precise decimal (10 digits, 2 after decimal)
- FLOAT, DOUBLE: Floating-point numbers
String:
- VARCHAR(255): Variable-length text
- CHAR(50): Fixed-length text
- TEXT: Large text blocks
- ENUM: Predefined values ('active', 'inactive')
Date/Time:
- DATE: Date only (YYYY-MM-DD)
- TIME: Time only (HH:MM:SS)
- DATETIME: Date and time
- TIMESTAMP: Automatic timestamp
Other:
- BOOLEAN: True/False (stored as 0/1)
- JSON: JSON document storage
Security Best Practices
- User Accounts: Create separate users for different apps. Use strong, unique passwords. Disable unused accounts.
- Network Access: Use firewall to restrict access. Allow only necessary IP addresses. Use VPN for remote access.
- Data Protection: Use parameterized queries to prevent SQL injection. Encrypt sensitive data. Regular backups.
- Credentials: Never hardcode passwords. Use environment variables. Don't commit to version control.
- Monitoring: Monitor failed login attempts. Check query logs for anomalies. Set up alerts for unusual activity.