ballerina/mysql package

Package overview

This package provides the functionality required to access and manipulate data stored in a MySQL database.

Endpoint

To access a database, you must first create an endpoint, which is a virtual representation of the physical endpoint of the MySQL database that you are trying to connect to. Create an endpoint of the MySQL client type (i.e., mysql:Client) and provide the necessary connection parameters. This will create a pool of connections to the given MySQL database. A sample for creating an endpoint with MySQL client can be found below.

Database operations

Once the endpoint is created, database operations can be executed through that endpoint. This package provides support for creating tables and executing stored procedures. It also supports selecting, inserting, deleting, updating, and batch updating data. For more details on the supported actions refer to the jdbc package. Details of the SQL data types and query parameters relevant to these database operations can be found in the documentation of the sql` package.

Samples

Creating an endpoint

endpoint mysql:Client testDB {
    host: "localhost",
    port: 3306,
    name: "testdb",
    username: "root",
    password: "root",
    poolOptions: { maximumPoolSize: 5 },
    dbOptions: { useSSL: false }
};

The full list of endpoint properties can be found in the sql:PoolOptions type.

Records Summary

Record Description
ClientEndpointConfiguration

The Client endpoint configuration for mysql databases.

Objects Summary

Object Description
Client

Represents an MySQL client endpoint.

public type ClientEndpointConfiguration

The Client endpoint configuration for mysql databases.

Field Name Data Type Default Value Description
host string

The host name of the database to connect

port int 3306

The port of the database to connect

name string

The name of the database to connect

username string

Username for the database connection

password string

Password for the database connection

poolOptions ballerina.sql:PoolOptions

Properties for the connection pool configuration

dbOptions map

DB specific properties

public type Client object

Represents an MySQL client endpoint.