Skip to main content

MySQL Configuration

Connect to MySQL databases for transactional data, structured queries, and OLTP systems.

Connection Parameters

Required Fields

FieldDescriptionExample
HostDatabase hostnamemysql.example.com
PortMySQL port (default: 3306)3306
DatabaseDatabase namemyapp
UsernameDatabase userapp_user
PasswordUser password (encrypted at rest)

Optional Fields

FieldDescription
Use SSLEnable for secure connections (recommended for production)

Connection String Format

mysql://user:***@host:3306/database

Configuration Example

When creating a MySQL data source, provide the following information:

FieldExample ValueNotes
Data source labelprod-mysqlKebab-case unique identifier (used as both name and label)
Hostmysql.example.comDatabase hostname
Port3306Default MySQL port
DatabasemyappDatabase name
Usernameapp_userDatabase user
PasswordpasswordEncrypted at rest
Use SSLEnabledRecommended for production

Test Connection

When you create or test a MySQL data source, the platform connects using the mysql2/promise driver and executes SELECT 1 to verify connectivity. The connection uses a 10-second timeout. If SSL is enabled, an empty SSL options object is passed (accepting all certificates).

MySQL-compatible databases (SingleStore, TimescaleDB, CrateDB) use the same test connection logic via the MySQL wire protocol.

Schema Discovery

MySQL has full native schema discovery support. Clicking Refresh Metadata returns:

  • Tables: All tables in the selected database (via SHOW TABLES)
  • Databases: All non-system databases (excluding information_schema, performance_schema, mysql, sys)
  • Size: Total data + index size from information_schema.tables
  • Row count: Approximate row count from information_schema.tables

Column-Level Metadata

You can fetch column details for individual tables, which returns:

  • Column name, data type, and column type
  • Nullability
  • Column key (PRIMARY, etc.)
  • Default values and extra information (e.g., auto_increment)
  • Table row count and size

Usage in Workflows (STRONGLY_SERVICES)

When a MySQL data source is attached to a workflow, credentials are injected via STRONGLY_SERVICES with all fields at the top level (not nested under a credentials key):

{
"datasources": {
"prod_mysql": {
"type": "mysql",
"name": "prod-mysql",
"host": "mysql.example.com",
"port": 3306,
"database": "myapp",
"username": "app_user",
"password": "actual_password",
"ssl": true,
"connectionString": "mysql://app_user:actual_password@mysql.example.com:3306/myapp"
}
}
}

Python Example

import os, json
import mysql.connector

# Parse STRONGLY_SERVICES environment variable
services = json.loads(os.getenv('STRONGLY_SERVICES', '{}'))
datasources = services.get('datasources', {})

# Get MySQL data source (key is sanitized name: hyphens become underscores)
my = datasources['prod_mysql']

# Connect using top-level credential fields
conn = mysql.connector.connect(
host=my['host'],
port=my['port'],
database=my['database'],
user=my['username'],
password=my['password'],
ssl_disabled=not my.get('ssl', False)
)

# Or use the connection string
# conn = mysql.connector.connect(my['connectionString'])

# Execute queries
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE active = 1")
users = cursor.fetchall()

Node.js Example

const mysql = require('mysql2/promise');

// Parse STRONGLY_SERVICES environment variable
const services = JSON.parse(process.env.STRONGLY_SERVICES || '{}');
const datasources = services.datasources || {};

// Get MySQL data source (key is sanitized name)
const my = datasources['prod_mysql'];

// Create connection using top-level fields
const connection = await mysql.createConnection({
host: my.host,
port: my.port,
database: my.database,
user: my.username,
password: my.password,
ssl: my.ssl ? {} : false
});

// Execute query
const [rows] = await connection.execute('SELECT * FROM users WHERE active = 1');
console.log(rows);

PHP Example

<?php
// Parse STRONGLY_SERVICES environment variable
$services = json_decode(getenv('STRONGLY_SERVICES'), true);
$datasources = $services['datasources'] ?? [];

// Get MySQL data source (key is sanitized name)
$my = $datasources['prod_mysql'];

// Connect using top-level credential fields
$mysqli = new mysqli(
$my['host'],
$my['username'],
$my['password'],
$my['database'],
$my['port']
);

// Check connection
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
}

// Execute query
$result = $mysqli->query("SELECT * FROM users WHERE active = 1");
$users = $result->fetch_all(MYSQLI_ASSOC);

SSL/TLS Configuration

Enabling SSL

To enable SSL for encrypted connections:

  1. Check the Use SSL checkbox when configuring the data source
  2. Ensure your MySQL server is configured with SSL certificates
  3. Verify the MySQL server requires SSL: SHOW VARIABLES LIKE 'have_ssl';

SSL Certificate Verification

For production environments, you may want to verify SSL certificates:

# Python with certificate verification
import ssl

ssl_context = ssl.create_default_context()
ssl_context.check_hostname = True
ssl_context.verify_mode = ssl.CERT_REQUIRED

conn = mysql.connector.connect(
host=my['host'],
port=my['port'],
database=my['database'],
user=my['username'],
password=my['password'],
ssl_disabled=False,
ssl_ca='/path/to/ca-cert.pem'
)

Common Issues

Connection Refused

  • Verify the host and port are correct
  • Check firewall rules allow connections
  • Ensure MySQL is listening on the correct interface (check bind-address in my.cnf)

Access Denied

  • Verify username and password are correct
  • Check user permissions: SHOW GRANTS FOR 'username'@'host';
  • Ensure the user is allowed to connect from the platform's IP address
  • Grant necessary privileges: GRANT ALL PRIVILEGES ON database.* TO 'username'@'host';

Database Not Found

  • Verify the database name is correct (case-sensitive on some systems)
  • Check if the database exists: SHOW DATABASES;
  • Create the database if needed: CREATE DATABASE myapp;

Too Many Connections

  • Check current connections: SHOW PROCESSLIST;
  • Increase max_connections in my.cnf if needed
  • Use connection pooling in your application

Best Practices

  1. Use SSL in Production: Always enable SSL for production databases
  2. Least Privilege: Create dedicated users with minimal required permissions
  3. Connection Pooling: Use connection pooling for better performance
  4. Character Encoding: Set proper character encoding (UTF-8/utf8mb4)
  5. Monitor Connections: Track connection usage and monitor for connection leaks
  6. Regular Testing: Periodically test connections to ensure they remain valid

Character Set Configuration

For proper Unicode support, ensure your database and tables use utf8mb4:

-- Create database with utf8mb4
CREATE DATABASE myapp
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

-- Convert existing database
ALTER DATABASE myapp
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;

-- Create table with utf8mb4
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(255)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;