diff --git a/lib/base/connection.js b/lib/base/connection.js index ea91f1813a..997bc177f1 100644 --- a/lib/base/connection.js +++ b/lib/base/connection.js @@ -37,6 +37,11 @@ class BaseConnection extends EventEmitter { constructor(opts) { super(); this.config = opts.config; + + if (typeof this.config.ssl === 'boolean' ) { + this.config.ssl = this.config.ssl === true ? {} : undefined; + } + // TODO: fill defaults // if no params, connect to /var/lib/mysql/mysql.sock ( /tmp/mysql.sock on OSX ) // if host is given, connect to host:3306 diff --git a/typings/mysql/lib/Connection.d.ts b/typings/mysql/lib/Connection.d.ts index dffc2a8ce2..b5db5aaae8 100644 --- a/typings/mysql/lib/Connection.d.ts +++ b/typings/mysql/lib/Connection.d.ts @@ -268,7 +268,7 @@ export interface ConnectionOptions { /** * object with ssl parameters or a string containing name of ssl profile */ - ssl?: string | SslOptions; + ssl?: string | boolean | SslOptions; /** * Return each row as an array, not as an object. diff --git a/website/docs/documentation/ssl.mdx b/website/docs/documentation/ssl.mdx index 59f6b07fa9..ee685c8334 100644 --- a/website/docs/documentation/ssl.mdx +++ b/website/docs/documentation/ssl.mdx @@ -10,12 +10,12 @@ See full list of [SslOptions](https://github.com/sidorares/node-mysql2/blob/mast ## SSL Options -To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify an empty object, for example: +To enable SSL without manually providing certificates and assuming they are already trusted by the host machine, you can specify `ssl: true` or `ssl: {}`, for example: ```ts const connection = await mysql.createConnection({ host: 'localhost', - ssl: {}, + ssl: true, }); ``` diff --git a/website/docs/examples/connections/create-connection.mdx b/website/docs/examples/connections/create-connection.mdx index 9f6a3a6f71..5ab4b0abd9 100644 --- a/website/docs/examples/connections/create-connection.mdx +++ b/website/docs/examples/connections/create-connection.mdx @@ -180,7 +180,7 @@ const mysql = require('mysql2'); const connection = mysql.createConnection({ // ... - ssl: {}, + ssl: true, }); connection.addListener('error', (err) => {