MySQL Protocol Support

MynaDB implements the MySQL wire protocol, allowing you to connect using any MySQL-compatible client. This enables seamless integration with existing tools like mysql-cli, DBeaver, Grafana, and more.

Configuration

Enable the MySQL protocol server in your config.toml:

toml
[mysql]
# Enable MySQL protocol server
enabled = true

# Port for MySQL connections (default: 3307)
port = 3307

# Bind address
bind = "0.0.0.0"

# Maximum concurrent connections
max_connections = 100

Connecting with MySQL CLI

bash
# Connect to MynaDB
mysql -h localhost -P 3307 -u root

# Connect to a specific database
mysql -h localhost -P 3307 -u root mydb

# Execute a query directly
mysql -h localhost -P 3307 -u root -e "SELECT * FROM mydb.default.cpu LIMIT 10"

Supported Commands

Database Commands

sql
-- List all databases (catalogs)
SHOW DATABASES;

-- Switch to a database
USE mydb;

-- Show current database
SELECT DATABASE();

Table Commands

sql
-- List all tables in current database
SHOW TABLES;

-- List tables in a specific schema
SHOW TABLES FROM default;

-- Show table schema
DESCRIBE cpu;
DESC cpu;

-- Show create table (schema info)
SHOW CREATE TABLE cpu;

Query Commands

sql
-- Standard SQL queries work as expected
SELECT host, AVG(usage) as avg_cpu
FROM cpu
WHERE time > NOW() - INTERVAL 1 HOUR
GROUP BY host
ORDER BY avg_cpu DESC;

-- Fully qualified table names
SELECT * FROM mydb.default.cpu LIMIT 10;

-- Time-based queries
SELECT
  time_bucket('5 minutes', time) as bucket,
  host,
  AVG(usage) as avg_usage
FROM cpu
GROUP BY bucket, host
ORDER BY bucket;

Connecting with GUI Tools

DBeaver

  1. Create a new connection: Database → New Database Connection
  2. Select "MySQL" as the database type
  3. Configure connection:
    • Host: localhost
    • Port: 3307
    • Database: mydb (or leave empty)
    • Username: root
    • Password: (leave empty or use configured password)
  4. Click "Test Connection" then "Finish"

Grafana

  1. Add a new data source
  2. Select "MySQL" as the type
  3. Configure:
    • Host: localhost:3307
    • Database: mydb
    • User: root
  4. Save & Test
text
Example Grafana Query:

SELECT
  $__timeGroup(time, $__interval) as ts,
  host,
  AVG(usage) as usage
FROM cpu
WHERE $__timeFilter(time)
GROUP BY ts, host
ORDER BY ts

DataGrip / IntelliJ

  1. File → New → Data Source → MySQL
  2. Configure:
    • Host: localhost
    • Port: 3307
    • User: root
  3. Test Connection and Apply

Python Connection

python
import mysql.connector

# Connect to MynaDB
conn = mysql.connector.connect(
    host="localhost",
    port=3307,
    user="root",
    database="mydb"
)

cursor = conn.cursor()

# Execute query
cursor.execute("""
    SELECT host, AVG(usage) as avg_cpu
    FROM cpu
    WHERE time > NOW() - INTERVAL 1 HOUR
    GROUP BY host
""")

# Fetch results
for row in cursor.fetchall():
    print(f"Host: {row[0]}, Avg CPU: {row[1]:.2f}%")

cursor.close()
conn.close()

Node.js Connection

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

async function query() {
  const conn = await mysql.createConnection({
    host: 'localhost',
    port: 3307,
    user: 'root',
    database: 'mydb'
  });

  const [rows] = await conn.execute(`
    SELECT host, AVG(usage) as avg_cpu
    FROM cpu
    WHERE time > NOW() - INTERVAL 1 HOUR
    GROUP BY host
  `);

  console.log(rows);
  await conn.end();
}

query();

Supported SQL Syntax

MynaDB supports standard SQL via Apache DataFusion. Key features include:

Limitations

The MySQL protocol implementation has some limitations:

Authentication

MynaDB supports basic authentication for MySQL connections:

toml
[mysql]
enabled = true
port = 3307

# Authentication (optional)
[mysql.auth]
enabled = true
username = "mynadb"
password = "secret123"
bash
# Connect with authentication
mysql -h localhost -P 3307 -u mynadb -psecret123