Skip to content

Commit a654cea

Browse files
thomasgauvinOxyjunelithrar
authored andcommitted
[Hyperdrive] MySQL for Hyperdrive changelog announcement (#21351)
* thomasgauvin: MySQL for Hyperdrive announcement * Apply suggestions from code review * Update src/content/changelog/hyperdrive/2025-04-08-hyperdrive-mysql-support.mdx Co-authored-by: Matt Silverlock <[email protected]> * adjust per pr comments * fix snippet issue * remove unnecessary file * nit to mysql support * Update src/content/changelog/hyperdrive/2025-04-08-hyperdrive-mysql-support.mdx Co-authored-by: Matt Silverlock <[email protected]> --------- Co-authored-by: Jun Lee <[email protected]> Co-authored-by: Matt Silverlock <[email protected]>
1 parent 007237a commit a654cea

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Hyperdrive introduces support for MySQL and MySQL-compatible databases
3+
description: You can now connect to MySQL databases from your Workers using Hyperdrive for optimal performance
4+
products:
5+
- hyperdrive
6+
date: 2025-04-08T14:00:00Z
7+
hidden: true
8+
---
9+
10+
import { Code } from "~/components";
11+
12+
Hyperdrive now supports connecting to MySQL and MySQL-compatible databases, including Amazon RDS and Aurora MySQL, Google Cloud SQL for MySQL, Azure Database for MySQL, PlanetScale and MariaDB.
13+
14+
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.
15+
16+
Best of all, you can connect using your existing drivers, ORMs, and query builders with Hyperdrive's secure credentials, no code changes required.
17+
18+
```ts
19+
import { createConnection } from "mysql2/promise";
20+
21+
export interface Env {
22+
HYPERDRIVE: Hyperdrive;
23+
}
24+
25+
export default {
26+
async fetch(request, env, ctx): Promise<Response> {
27+
const connection = await createConnection({
28+
host: env.HYPERDRIVE.host,
29+
user: env.HYPERDRIVE.user,
30+
password: env.HYPERDRIVE.password,
31+
database: env.HYPERDRIVE.database,
32+
port: env.HYPERDRIVE.port,
33+
disableEval: true, // Required for Workers compatibility
34+
});
35+
36+
const [results, fields] = await connection.query("SHOW tables;");
37+
38+
ctx.waitUntil(connection.end());
39+
40+
return new Response(JSON.stringify({ results, fields }), {
41+
headers: {
42+
"Content-Type": "application/json",
43+
"Access-Control-Allow-Origin": "*",
44+
},
45+
});
46+
},
47+
} satisfies ExportedHandler<Env>;
48+
```
49+
50+
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/).

0 commit comments

Comments
 (0)