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
- Create a new connection: Database → New Database Connection
- Select "MySQL" as the database type
- Configure connection:
- Host:
localhost - Port:
3307 - Database:
mydb(or leave empty) - Username:
root - Password: (leave empty or use configured password)
- Host:
- Click "Test Connection" then "Finish"
Grafana
- Add a new data source
- Select "MySQL" as the type
- Configure:
- Host:
localhost:3307 - Database:
mydb - User:
root
- Host:
- 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
- File → New → Data Source → MySQL
- Configure:
- Host:
localhost - Port:
3307 - User:
root
- Host:
- 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:
- SELECT with WHERE, GROUP BY, HAVING, ORDER BY, LIMIT
- Aggregations: COUNT, SUM, AVG, MIN, MAX, STDDEV, etc.
- Window Functions: ROW_NUMBER, RANK, LAG, LEAD, etc.
- Joins: INNER, LEFT, RIGHT, FULL OUTER
- Subqueries: Correlated and non-correlated
- CTEs: WITH clause for common table expressions
- Time Functions: NOW(), time_bucket(), date_trunc()
Limitations
The MySQL protocol implementation has some limitations:
- Read-only: INSERT/UPDATE/DELETE are not supported via MySQL protocol (use HTTP API for writes)
- No transactions: BEGIN/COMMIT/ROLLBACK are no-ops
- No stored procedures: Only ad-hoc SQL queries are supported
- No prepared statements with parameters: Use string interpolation for dynamic queries
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