interface ConnectionOptions {
    Promise?: any;
    authPlugins?: {
        [key: string]: AuthPlugin;
    };
    authSwitchHandler?: ((data: any, callback: (() => void)) => any);
    bigNumberStrings?: boolean;
    charset?: string;
    charsetNumber?: number;
    compress?: boolean;
    connectAttributes?: {
        [param: string]: any;
    };
    connectTimeout?: number;
    connectionLimit?: number;
    database?: string;
    dateStrings?: boolean | ("TIMESTAMP" | "DATETIME" | "DATE")[];
    debug?: any;
    decimalNumbers?: boolean;
    enableKeepAlive?: boolean;
    flags?: string[];
    host?: string;
    idleTimeout?: number;
    infileStreamFactory?: ((path: string) => Readable);
    insecureAuth?: boolean;
    isServer?: boolean;
    jsonStrings?: boolean;
    keepAliveInitialDelay?: number;
    localAddress?: string;
    maxIdle?: number;
    maxPreparedStatements?: number;
    multipleStatements?: boolean;
    namedPlaceholders?: boolean;
    nestTables?: string | boolean;
    password?: string;
    password1?: string;
    password2?: string;
    password3?: string;
    passwordSha1?: string;
    pool?: any;
    port?: number;
    queryFormat?: ((query: string, values: any) => void);
    queueLimit?: number;
    rowsAsArray?: boolean;
    socketPath?: string;
    ssl?: string | SslOptions;
    stream?: any;
    stringifyObjects?: boolean;
    supportBigNumbers?: boolean;
    timezone?: string;
    trace?: boolean;
    typeCast?: TypeCast;
    uri?: string;
    user?: string;
    waitForConnections?: boolean;
}

Hierarchy

  • PoolOptions
    • ConnectionOptions

Properties

Promise?: any
authPlugins?: {
    [key: string]: AuthPlugin;
}
authSwitchHandler?: ((data: any, callback: (() => void)) => any)
bigNumberStrings?: boolean

Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately represented with JavaScript Number objects (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects. This option is ignored if supportBigNumbers is disabled.

charset?: string

The charset for the connection. This is called 'collation' in the SQL-level of MySQL (like utf8_general_ci). If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used. (Default: 'UTF8_GENERAL_CI')

charsetNumber?: number
compress?: boolean
connectAttributes?: {
    [param: string]: any;
}
connectTimeout?: number

The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)

connectionLimit?: number

The maximum number of connections to create at once. (Default: 10)

database?: string

Name of the database to use for this connection

dateStrings?: boolean | ("TIMESTAMP" | "DATETIME" | "DATE")[]

Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date objects. Can be true/false or an array of type names to keep as strings.

(Default: false)

debug?: any

This will print all incoming and outgoing packets on stdout. You can also restrict debugging to packet types by passing an array of types (strings) to debug;

(Default: false)

decimalNumbers?: boolean

DECIMAL and NEWDECIMAL types will be returned as numbers if this option is set to true ( default: false).

enableKeepAlive?: boolean

Enable keep-alive on the socket. (Default: true)

flags?: string[]

List of connection flags to use other than the default ones. It is also possible to blacklist default ones

host?: string

The hostname of the database you are connecting to. (Default: localhost)

idleTimeout?: number

The idle connections timeout, in milliseconds. (Default: 60000)

infileStreamFactory?: ((path: string) => Readable)

By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.

insecureAuth?: boolean

Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)

isServer?: boolean
jsonStrings?: boolean

Force JSON to be returned as string

(Default: false)

keepAliveInitialDelay?: number

If keep-alive is enabled users can supply an initial delay. (Default: 0)

localAddress?: string

The source IP address to use for TCP connection

maxIdle?: number

The maximum number of idle connections. (Default: same as connectionLimit)

maxPreparedStatements?: number
multipleStatements?: boolean

Allow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)

namedPlaceholders?: boolean
nestTables?: string | boolean
password?: string

The password of that MySQL user

password1?: string

Alias for the MySQL user password. Makes a bit more sense in a multifactor authentication setup (see "password2" and "password3")

password2?: string

2nd factor authentication password. Mandatory when the authentication policy for the MySQL user account requires an additional authentication method that needs a password. https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html

password3?: string

3rd factor authentication password. Mandatory when the authentication policy for the MySQL user account requires two additional authentication methods and the last one needs a password. https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html

passwordSha1?: string
pool?: any
port?: number

The port number to connect to. (Default: 3306)

queryFormat?: ((query: string, values: any) => void)

A custom query format function

queueLimit?: number

The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there is no limit to the number of queued connection requests. (Default: 0)

rowsAsArray?: boolean

Return each row as an array, not as an object. This is useful when you have duplicate column names. This can also be set in the QueryOption object to be applied per-query.

socketPath?: string

The path to a unix domain socket to connect to. When used host and port are ignored

ssl?: string | SslOptions

object with ssl parameters or a string containing name of ssl profile

stream?: any
stringifyObjects?: boolean

Stringify objects instead of converting to values. (Default: 'false')

supportBigNumbers?: boolean

When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option (Default: false)

timezone?: string

The timezone used to store local dates. (Default: 'local')

trace?: boolean

Generates stack traces on Error to include call site of library entrance ('long stack traces'). Slight performance penalty for most calls. (Default: true)

typeCast?: TypeCast

Determines if column values should be converted to native JavaScript types.

true

It is not recommended (and may go away / change in the future) to disable type casting, but you can currently do so on either the connection or query level.


You can also specify a function to do the type casting yourself:

(field: Field, next: () => void) => {
return next();
}

WARNING:

YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once:

field.string();
field.buffer();
field.geometry();

Which are aliases for:

parser.parseLengthCodedString();
parser.parseLengthCodedBuffer();
parser.parseGeometryValue();

You can find which field function you need to use by looking at RowDataPacket.prototype._typeCast.

uri?: string
user?: string

The MySQL user to authenticate as

waitForConnections?: boolean

Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue the connection request and call it when one becomes available. If false, the pool will immediately call back with an error. (Default: true)