Static IP guide

Connecting to MySQL with a static IP from a Node app on Vercel

MySQL hosts that enforce allowlists — RDS, Cloud SQL, Azure Database for MySQL — cannot admit Vercel's rotating egress IPs. mysql2 accepts a custom stream, so each function invocation opens a SOCKS connection through Fixie and the database sees a stable address instead.

RuntimeNode.js and JavaScript
PlatformVercel
DestinationMySQL
Fixie productFixie Vercel integration

Recommended setup

Use Fixie Vercel integration for MySQL or MariaDB connections from a dynamic hosting platform. Store the proxy value in FIXIE_SOCKS_HOST, then configure Node.js to route outbound traffic through Fixie before connecting to MySQL.

Set up Fixie on Vercel

Add the Fixie Vercel integration, create a proxy in the Fixie dashboard, and connect it to the Vercel project and environment. The integration can create FIXIE_SOCKS_HOST in Vercel Environment Variables for the connected project.

Pull Vercel environment variables locally

vercel env pull
grep FIXIE_SOCKS_HOST .env.local

Implementation

The example below shows the core application-side change. Keep credentials in environment variables and avoid committing proxy, database, or API secrets.

Connect to MySQL through FIXIE_SOCKS_HOST

const mysql = require('mysql2');
const SocksConnection = require('socksjs');

const fixieValues = process.env.FIXIE_SOCKS_HOST.split(new RegExp('[/(:\\/@)/]+'));

const mysqlServer = {
  host: 'mysql.example.com',
  port: 3306,
};

const fixieConnection = new SocksConnection(mysqlServer, {
  user: fixieValues[0],
  pass: fixieValues[1],
  host: fixieValues[2],
  port: fixieValues[3],
});

const pool = mysql.createPool({
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  stream: fixieConnection,
});

pool.query('select version()', (error, rows) => {
  if (error) throw error;
  console.log(rows);
});

Good to know

  • The pooled example suits long-lived servers; in a function, create a connection per invocation and end it before returning.
  • Keep TLS enabled toward the database; the SOCKS tunnel wraps the encrypted session without terminating it.

Allowlist and test the static IPs

  1. Open the Fixie dashboard and copy the outbound IP addresses for this proxy.
  2. Add both IPs to the MySQL firewall or security group.
  3. Deploy the updated Node.js app on Vercel.
  4. Run a small connection test before sending production traffic.

Related guides

Related docs