---
title: "Cloudflare Hyperdrive - Global Database Acceleration"
description: "Make your database feel instant, everywhere. Connection pooling, query caching, and global routing for PostgreSQL and MySQL databases."
url: "https://www.cloudflare.com/products/hyperdrive"
---

# Hyperdrive

> Hyperdrive makes regional databases feel global. Connection pooling provides 3x faster queries from globally-distributed Workers, with optional caching for 100x speed and scale on repeated queries.

## Key Features

- PostgreSQL and MySQL support
- Connection pooling
- Query result caching
- Works with any database driver
- ORM compatible (Prisma, Drizzle, etc.)
- No database modifications required
- Regional connection pools

## Benefits

### Zero Migration

Change the connection string, keep everything else

### Compatible

Works with PostgreSQL, MySQL, and popular ORMs

### Fast

Sub-5ms cached query results and global pooling

## Use Cases

### Build fast, global, full-stack

Build full-stack Workers applications that feel fast everywhere by eliminating the distance penalty between global compute and regional data. No complex multi-region database setups required.

### Scale read-heavy applications globally

Handle millions of database queries without overwhelming your database. Connection pooling and query caching distribute load.

### Cache database queries at the edge

Store frequently-accessed data like user profiles, configuration settings, and routing tables at 330+ locations worldwide. Perfect for authentication, authorization, and edge decision-making.

### Compatible with your existing stack

Swap your connection string - and that's it. Build with your existing databases, drivers, ORMs and libraries. Scale your app globally, no major re-architecture required.

## Code Examples

### Connect to PostgreSQL, MySQL, or compatible databases

Use your existing drivers, ORMs and libraries with Hyperdrive. Just swap your direct connection string with Hyperdrive's connection string.

```typescript
// Use your existing drivers, ORMs and libraries
import postgres from 'postgres';

export default {
async fetch(request, env, ctx): Promise<Response> {
  // Just swap your direct connection string with Hyperdrive's connection string
  const sql = postgres(env.HYPERDRIVE.connectionString);
  const results = await sql`SELECT * FROM pg_tables`;
}
}
```

### Connect to PostgreSQL from Workers

Connect directly to your regional PostgreSQL database using Hyperdrive's connection string. Connections are pooled globally and routed over Cloudflare's network for lower latency and higher concurrency.

```typescript
import postgres from 'postgres';

export default {
  async fetch(request, env, ctx): Promise<Response> {
    const sql = postgres(env.HYPERDRIVE.connectionString);

      try {
        const results = await sql`SELECT * FROM pg_tables`;
        ctx.waitUntil(sql.end());

        return Response.json(results);
      } catch (e) {
        return Response.json({ error: e instanceof Error ? e.message : e }, { status: 500 });
      }
    },
} satisfies ExportedHandler<Env>;
```

### Connect to MySQL from Workers

Use familiar MySQL drivers to query your existing databases through Hyperdrive. Benefit from global pooling and edge routing without changing your query logic or schema.

```typescript
import { createConnection  } from 'mysql2/promise';

export default {
  async fetch(request, env, ctx): Promise<Response> {
    const connection = await createConnection({
     host: env.DB_HOST,
     user: env.DB_USER,
     password: env.DB_PASSWORD,
     database: env.DB_NAME,
     port: env.DB_PORT,
     disableEval: true
  });

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

  return new Response(JSON.stringify({ results, fields }), {
    headers: {
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin': '*',
    },
  });
}} satisfies ExportedHandler<Env>;
```

## Resources

- [Full Documentation](https://developers.cloudflare.com/hyperdrive): Complete technical documentation
- [Get Started](https://dash.cloudflare.com/sign-up): Sign up and start building
- [Pricing](/plans.md): See pricing details

## Related Products

- [Artifacts](/products/artifacts.md): Git-native versioned storage
- [Cache Reserve](/products/cache-reserve.md): Persistent caching for static content
- [D1](/products/d1.md): Serverless SQL
- [Data Platform](/products/data-platform.md): Ingest, Catalog & Query

---

*This is a markdown version of [https://www.cloudflare.com/products/hyperdrive](https://www.cloudflare.com/products/hyperdrive) for AI/LLM consumption.*
