Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/docs/documentation/00-index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Not only **MySQL2** offers better performance over [Node MySQL][node-mysql], we
- [More Features](/docs/documentation/extras)
- [MySQL Server](/docs/documentation/mysql-server)
- Pooling
- SSL
- [SSL](/docs/documentation/ssl)
- MySQL Compression
- Binary Log Protocol Client

Expand Down
70 changes: 70 additions & 0 deletions website/docs/documentation/ssl.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SSL

As part of the connection options one can specify an object with ssl parameters or a string containing name of SSL profile.

```ts
ssl?: string | SslOptions;
```

See full list of [SslOptions](../../../typings/mysql/lib/Connection.d.ts), which are in the same format as [tls.createSecureContext](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options).

## SSL Options

To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify empty object:

```ts
const connection = mysql.createConnection({
host: 'localhost',
ssl: {}
});
```

You can also specify custom certificate(s) as an individual string or array of strings. Please note the arguments expect a string of the certificate, not a file name to the certificate:

```ts
const connection = mysql.createConnection({
host: 'localhost',
ssl: {
ca: fs.readFileSync(__dirname + '/mysql-ca.crt')
}
});
```

When cerificate is read from environment variable, you might need to replace escaped `\n` characters with proper new line characters:

```ts
const connection = mysql.createConnection({
host: 'localhost',
ssl: {
ca: process.env.DB_SSL_CA?.replace(/\\n/gm, '\n')
}
});
```

You can also connect to a MySQL server without properly providing an appropriate CA to trust. **This is highly discouraged** as being insecure.

```ts
const connection = mysql.createConnection({
host: 'localhost',
ssl: {
// DO NOT DO THIS
// set up your ca correctly to trust the connection
rejectUnauthorized: false
}
});
```

## SSL Profile (deprecated)

Alternativelly you can also specify a string containing name of SSL profile:

```ts
const connection = mysql.createConnection({
host: 'localhost',
ssl: 'Amazon RDS'
});
```

Following profiles are included in the package:

* `Amazon RDS` - contains certificates from https://rds.amazonaws.com/doc/rds-ssl-ca-cert.pem and https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
Loading