Static IP guide

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

MySQL grants are commonly restricted by host, and cloud MySQL firewalls (RDS, Cloud SQL, Azure Database) expect a fixed caller address — something a Heroku dyno cannot promise. With Fixie Socks, mysql2 accepts a SOCKS connection as its stream, so your app presents Fixie's static IPs to the database while the driver API stays the same.

RuntimeNode.js and JavaScript
PlatformHeroku
DestinationMySQL
Fixie productFixie Socks Heroku add-on

Recommended setup

Use Fixie Socks Heroku add-on 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 Heroku

Heroku is a native Fixie marketplace flow. Install the Fixie Socks Heroku add-on or attach it from the Heroku CLI. Heroku will create FIXIE_SOCKS_HOST as a config var for the app.

Attach fixie-socks to your Heroku app

heroku addons:create fixie-socks
heroku config:get FIXIE_SOCKS_HOST

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

  • Use a connection pool — pooling is already a best practice for this kind of workload and keeps reconnects out of your query path.
  • The database sees Fixie's IP, not the dyno's — so host-restricted grants and firewall rules should reference the two IPs from your Fixie dashboard.

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 Heroku.
  4. Run a small connection test before sending production traffic.

Related guides

Related docs