Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: Hyperdrive introduces support for MySQL and MySQL-compatible databases
description: You can now connect to MySQL databases from your Workers using Hyperdrive for optimal performance
products:
- hyperdrive
date: 2025-04-08T14:00:00Z
---

import { Code } from "~/components";

Hyperdrive now supports connecting to MySQL and MySQL-compatible databases, including Amazon RDS MySQL, Google Cloud SQL for MySQL, Azure Database for MySQL, and PlanetScale.

Hyperdrive makes your regional, MySQL databases fast when connecting from Cloudflare Workers. It eliminates unnecessary network roundtrips during connection setup, pools database connections globally, and can cache query results to provide the fastest possible response times.

Best of all, you can connect using your existing drivers, ORMs, and query builders with Hyperdrive's secure credentials, no code changes required.

import mysqlRaw from "~/content/partials/hyperdrive/mysql-snippet-slim.mdx?raw";

<Code code={mysqlRaw} lang="typescript" />

Learn more about [how Hyperdrive works](/hyperdrive/configuration/how-hyperdrive-works/) and [get started building Workers that connect to MySQL with Hyperdrive](/hyperdrive/get-started/).
29 changes: 29 additions & 0 deletions src/content/partials/hyperdrive/mysql-snippet-slim.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createConnection } from "mysql2/promise";

export interface Env {
HYPERDRIVE: Hyperdrive;
}

export default {
async fetch(request, env, ctx): Promise<Response> {
const connection = await createConnection({
host: env.HYPERDRIVE.host,
user: env.HYPERDRIVE.user,
password: env.HYPERDRIVE.password,
database: env.HYPERDRIVE.database,
port: env.HYPERDRIVE.port,
disableEval: true, // Required for Workers compatibility
});

const [results, fields] = await connection.query("SHOW tables;");

ctx.waitUntil(connection.end());

return new Response(JSON.stringify({ results, fields }), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
});

}} satisfies ExportedHandler<Env>;
Loading