MySQL
Fully managed MySQL databases with automatic backups, replication, and scaling.
Overview
Sparbz Cloud MySQL provides production-ready MySQL databases with high availability, automated backups, and seamless scaling.
Features
- High Availability: Automatic failover with synchronous replication
- Automated Backups: Point-in-time recovery with configurable retention
- Read Replicas: Scale read workloads with replica instances
- Monitoring: Built-in metrics and slow query analysis
- Security: Encryption at rest and in transit, VPC isolation
Versions
| Version | Status | End of Life |
|---|---|---|
| MySQL 8.4 | Current | 2032 |
| MySQL 8.0 | Supported | 2026 |
Tiers
| Tier | vCPU | Memory | Storage | Connections |
|---|---|---|---|---|
| Starter | 1 | 2 GB | 10 GB | 100 |
| Pro | 2 | 8 GB | 100 GB | 500 |
| Enterprise | 4+ | 32+ GB | 1 TB+ | 5000+ |
Getting Started
Create a Database
# Create a MySQL database
szc database create my-mysql --engine mysql
# Create with specific version
szc database create my-mysql --engine mysql --version 8.4
# Create with pro tier
szc database create my-mysql --engine mysql --tier pro
# Wait for database to be ready
szc database create my-mysql --engine mysql --wait
Get Connection Details
# Get connection info
szc database get my-mysql
# Get connection string only
szc database get my-mysql --json --fields connection_string
# Get credentials
szc database credentials my-mysql
Connect to Database
# Using mysql client
mysql -h <host> -P 3306 -u <username> -p<password> <database>
# Using connection string
mysql mysql://<username>:<password>@<host>:3306/<database>
Connection Examples
Node.js with mysql2
const mysql = require('mysql2/promise');
const connection = await mysql.createConnection({
host: '<host>',
port: 3306,
user: '<username>',
password: '<password>',
database: '<database>',
ssl: {
rejectUnauthorized: true
}
});
const [rows] = await connection.execute('SELECT * FROM users WHERE id = ?', [1]);
Python with pymysql
import pymysql
connection = pymysql.connect(
host='<host>',
port=3306,
user='<username>',
password='<password>',
database='<database>',
ssl={'ssl': True}
)
with connection.cursor() as cursor:
cursor.execute("SELECT * FROM users WHERE id = %s", (1,))
result = cursor.fetchone()
Go with go-sql-driver/mysql
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
dsn := "<username>:<password>@tcp(<host>:3306)/<database>?tls=true"
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatal(err)
}
defer db.Close()
var name string
err = db.QueryRow("SELECT name FROM users WHERE id = ?", 1).Scan(&name)
Java with JDBC
import java.sql.*;
String url = "jdbc:mysql://<host>:3306/<database>?useSSL=true";
Connection conn = DriverManager.getConnection(url, "<username>", "<password>");
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
stmt.setInt(1, 1);
ResultSet rs = stmt.executeQuery();
Database Management
Upgrade Version
# Upgrade to latest minor version
szc database upgrade my-mysql
# Upgrade to specific version
szc database upgrade my-mysql --version 8.4
Scale Resources
# Scale to pro tier
szc database scale my-mysql --tier pro
# Scale storage
szc database scale my-mysql --storage 200
Delete Database
# Delete database (creates final backup)
szc database delete my-mysql
# Delete without backup
szc database delete my-mysql --skip-final-backup
# Force delete
szc database delete my-mysql --force
Backups
Automatic Backups
All databases include automatic daily backups with configurable retention:
| Tier | Retention | Point-in-Time |
|---|---|---|
| Starter | 7 days | No |
| Pro | 30 days | Yes |
| Enterprise | 90 days | Yes |
Manual Backups
# Create manual backup
szc backup create my-mysql --type database
# List backups
szc backup list --resource my-mysql
# Restore from backup
szc backup restore bkp_abc123 --target my-mysql-restored
Point-in-Time Recovery
# Restore to specific point in time (Pro/Enterprise only)
szc database restore my-mysql --point-in-time "2024-01-15T10:30:00Z"
Read Replicas
Create read replicas for scaling read-heavy workloads:
# Create read replica
szc database replica create my-mysql my-mysql-replica
# List replicas
szc database replica list my-mysql
# Promote replica to primary
szc database replica promote my-mysql-replica
Monitoring
Available Metrics
- CPU utilization
- Memory usage
- Storage usage and IOPS
- Connection count
- Slow queries
- Replication lag (replicas)
View Metrics
# Get current metrics
szc database metrics my-mysql
# Get metrics for specific period
szc database metrics my-mysql --start "2024-01-15T00:00:00Z" --end "2024-01-16T00:00:00Z"
Slow Query Log
# Enable slow query log
szc database config my-mysql --set slow_query_log=ON --set long_query_time=1
# View slow queries
szc database slow-queries my-mysql
Configuration
Configurable Parameters
| Parameter | Default | Description |
|---|---|---|
| max_connections | 100/500/5000 | Maximum client connections |
| innodb_buffer_pool_size | 75% memory | Buffer pool size |
| slow_query_log | OFF | Enable slow query logging |
| long_query_time | 10 | Slow query threshold (seconds) |
| character_set_server | utf8mb4 | Default character set |
| collation_server | utf8mb4_0900_ai_ci | Default collation |
Update Configuration
# Set single parameter
szc database config my-mysql --set max_connections=200
# Set multiple parameters
szc database config my-mysql \
--set max_connections=200 \
--set slow_query_log=ON \
--set long_query_time=2
Security
Network Access
Databases are only accessible within your VPC by default. Enable public access if needed:
# Enable public access (not recommended for production)
szc database config my-mysql --public-access
User Management
# Create additional user
szc database user create my-mysql app_user
# Create read-only user
szc database user create my-mysql readonly_user --privileges SELECT
# Rotate password
szc database user rotate-password my-mysql app_user
Encryption
- At rest: AES-256 encryption using managed keys
- In transit: TLS 1.3 required for all connections
Migration
Import Data
# Import from SQL dump
mysql -h <host> -P 3306 -u <username> -p<password> <database> < dump.sql
# Import using mysqlimport
mysqlimport --host=<host> --port=3306 --user=<username> \
--password=<password> --ssl <database> data.csv
Export Data
# Export database
mysqldump -h <host> -P 3306 -u <username> -p<password> <database> > dump.sql
# Export specific tables
mysqldump -h <host> -P 3306 -u <username> -p<password> <database> users orders > tables.sql
Best Practices
Performance
- Use InnoDB for all tables
- Create appropriate indexes for query patterns
- Use connection pooling in applications
- Monitor and optimize slow queries
Security
- Use dedicated users per application
- Grant minimal required privileges
- Rotate credentials regularly
- Keep public access disabled
Reliability
- Enable automated backups
- Test backup restoration periodically
- Use read replicas for disaster recovery
- Monitor replication lag
Pricing
| Tier | Monthly | Included Storage | Overage |
|---|---|---|---|
| Starter | $15 | 10 GB | $0.10/GB |
| Pro | $49 | 100 GB | $0.08/GB |
| Enterprise | Custom | Custom | Custom |
Backup storage is billed separately at $0.05/GB/month.