sidorares/node-mysql2 · error · TypeError
Unknown SSL profile '${name}'
Error message
Unknown SSL profile '${name}' What it means
ConnectionConfig.getSSLProfile() looks up the provided profile name in the built-in SSL profiles map (lib/constants/ssl_profiles.js). If the name is not a key in that map, mysql2 does not know the profile and throws. The string form of `ssl` is only for the small set of named profiles bundled with the library (commonly none or a few well-known CA bundles); custom TLS settings must be passed as an object.
Source
Thrown at lib/connection_config.js:270
return defaultFlags;
}
static getCharsetNumber(charset) {
const num = Charsets[charset.toUpperCase()];
if (num === undefined) {
throw new TypeError(`Unknown charset '${charset}'`);
}
return num;
}
static getSSLProfile(name) {
if (!SSLProfiles) {
SSLProfiles = require('./constants/ssl_profiles.js');
}
const ssl = SSLProfiles[name];
if (ssl === undefined) {
throw new TypeError(`Unknown SSL profile '${name}'`);
}
return ssl;
}
static parseUrl(url) {
const parsedUrl = new URL(url);
const options = {
host: decodeURIComponent(parsedUrl.hostname),
port: parseInt(parsedUrl.port, 10),
database: decodeURIComponent(parsedUrl.pathname.slice(1)),
user: decodeURIComponent(parsedUrl.username),
password: decodeURIComponent(parsedUrl.password),
};
for (const [key, value] of parsedUrl.searchParams) {
if (key in options) {
continue;
}
try {View on GitHub (pinned to 5ebe8903d6)
Solutions
- Pass the TLS options as an object directly: `ssl: { ca: fs.readFileSync('rds-ca.pem') }`.
- If you intended a named profile, verify it exists in lib/constants/ssl_profiles.js for your mysql2 version.
- Omit `ssl` or set it to `false` if you do not need TLS.
Example fix
// before
mysql.createConnection({ host, user, password, ssl: 'AmazonRDS' });
// after
const fs = require('fs');
mysql.createConnection({
host,
user,
password,
ssl: { ca: fs.readFileSync('rds-ca-cert.pem') },
}); Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
function buildSsl(profileOrObject) {
if (typeof profileOrObject === 'string') {
// only use a string if you know it exists in lib/constants/ssl_profiles.js
return profileOrObject;
}
if (profileOrObject && typeof profileOrObject === 'object') {
return profileOrObject; // e.g. { ca: fs.readFileSync('cert.pem') }
}
throw new TypeError('ssl must be a known profile string or a TLS options object');
} Type guard
function isSslObject(ssl) {
return typeof ssl === 'string' || (typeof ssl === 'object' && ssl !== null && !Array.isArray(ssl));
} Prevention
- Prefer passing a TLS options object with your CA bundle rather than a profile name.
- Do not assume a named profile is bundled — check ssl_profiles.js for your version.
- Load certificates from files into the object form for portability.
When it happens
Trigger: Passing `ssl: 'AmazonRDS'` or another string that is not present in the bundled ssl_profiles map. Most mysql2 installs ship an empty or minimal profile set, so almost any string other than a documented key will throw.
Common situations: Following an outdated tutorial referencing a named profile that was removed or never bundled; assuming `ssl: 'rds'` works; using a profile name from a different driver.
Related errors
- SSL profile must be an object, instead it's a ${typeof this.
- Unknown charset '${charset}'
- "user" connection config property must be a string
- "database" connection config property must be a string
AI-assisted analysis of sidorares/node-mysql2@5ebe8903d6 (2026-08-03).
Data as JSON: /data/errors/1e9815e0af86db81.json.
Report an issue: GitHub.