MySQL connection using the official driver.

Implements: IReferenceable, IConfigurable, IOpenable


The MySqlConnection class allows you to create a connection to a MySQL database using a plain driver.

Configuration parameters


  • discovery_key: (optional) key to retrieve the connection from IDiscovery
  • host: host name or IP address
  • port: port number (default: 27017)
  • uri: resource URI or connection string with all parameters in it


  • store_key: (optional) key to retrieve the credentials from ICredentialStore
  • username: username
  • password: user’s password


  • connect_timeout: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0)
  • idle_timeout: (optional) number of milliseconds a client must sit idle in the pool and not be checked out (default: 10000)
  • max_pool_size: (optional) maximum number of clients the pool should contain (default: 10)


  • *:logger:*:*:1.0 - (optional) ILogger components to pass log messages
  • *:discovery:*:*:1.0 - (optional) IDiscovery services
  • *:credential-store:*:*:1.0 (optional) credential stores to resolve credentials



The MySQL connection pool object.

protected _connection: any


The connection resolver.

protected _connectionResolver: MySqlConnectionResolver


The MySQL database name.

protected _databaseName: string


The logger.

protected _logger: CompositeLogger


The configuration options.

protected _options: ConfigParams

Instance methods


Closes the component and frees used resources.

public close(correlationId: string): Promise<void>

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.


Configures the component by passing configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.


Gets the connection.

public getConnection(): any

  • returns: any - connection to a MySQL database


Gets the database name

public getDatabaseName(): string

  • returns: string - database name


Checks if the component is opened.

public isOpen(): boolean

  • returns: boolean - True if the component has been opened and False otherwise.


Opens the component.

public open(correlationId: string): Promise<void>

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.


Sets references to dependent components.

public setReferences(references: IReferences): void

  • references: IReferences - references to locate the component dependencies.