BackendDatabases
MySQL
Connect to MySQL databases.
Connect to a MySQL database and get full CRUD through a direct mysql2 driver connection.
import { createEngine } from '@superapp/backend'
const engine = createEngine({
connections: {
warehouse: process.env.MYSQL_URL!,
},
})Connection URL Format
Standard MySQL connection string:
mysql://user:password@host:3306/database| Parameter | Description |
|---|---|
user | Database user |
password | Database password |
host | Server hostname or IP |
3306 | Port (default: 3306) |
database | Database name |
How It Works
When the engine starts, it detects the mysql:// protocol and initializes a connection pool using the mysql2 driver. All tables in the target database become available under the warehouse namespace. Queries are executed directly against MySQL with no intermediary.
Capabilities
| Operation | Supported |
|---|---|
findMany / findOne | Yes |
create | Yes |
update | Yes |
delete | Yes |
count / aggregate | Yes |
| Transactions | Yes |
Full Example
import { createEngine } from '@superapp/backend'
import { createHonoMiddleware } from '@superapp/backend/adapters/hono'
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
const engine = createEngine({
connections: {
warehouse: process.env.MYSQL_URL!,
},
permissions: {
customers: {
table: 'warehouse.customers',
select: {
roles: ['viewer'],
columns: ['id', 'name', 'email', 'created_at'],
},
},
},
})
const app = new Hono()
app.route('/', createHonoMiddleware(engine))
serve({ fetch: app.fetch, port: 3001 })Combining with Other Providers
MySQL works alongside any other provider. A common pattern is Postgres for your primary database and MySQL for a legacy warehouse:
const engine = createEngine({
connections: {
main: process.env.PG_URL!,
warehouse: process.env.MYSQL_URL!,
},
})Tables are namespaced: main.orders, warehouse.customers.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Connection refused | MySQL not reachable | Check host, port, and firewall rules |
Access denied | Wrong credentials | Verify user/password in connection URL |
Unknown database | Database does not exist | Check database name in the URL |
Too many connections | Pool exhausted on MySQL side | Increase max_connections in MySQL config |
SSL required | Server enforces SSL | Add ?ssl-mode=REQUIRED to the URL |