superapp
BackendDatabases

MySQL

Connect to MySQL databases.

Chat in Claude

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
ParameterDescription
userDatabase user
passwordDatabase password
hostServer hostname or IP
3306Port (default: 3306)
databaseDatabase 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

OperationSupported
findMany / findOneYes
createYes
updateYes
deleteYes
count / aggregateYes
TransactionsYes

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

ProblemCauseFix
Connection refusedMySQL not reachableCheck host, port, and firewall rules
Access deniedWrong credentialsVerify user/password in connection URL
Unknown databaseDatabase does not existCheck database name in the URL
Too many connectionsPool exhausted on MySQL sideIncrease max_connections in MySQL config
SSL requiredServer enforces SSLAdd ?ssl-mode=REQUIRED to the URL

On this page