All Products
Search
Document Center

Lindorm:Develop applications by using Node.js

Last Updated:Mar 28, 2026

Use the MySQL2 driver to connect a Node.js application to LindormTable over the MySQL compatibility protocol. This guide walks you through installing the driver, configuring your connection, and running your first query.

Prerequisites

Before you begin, ensure that you have:

Install the MySQL2 driver

Run the following command to install the MySQL2 driver:

npm install mysql2

Connect to LindormTable

Step 1: Set connection parameters

Store your credentials in environment variables to avoid hardcoding sensitive values in your code:

export LINDORM_HOST=<your-mysql-endpoint>
export LINDORM_USER=<your-username>
export LINDORM_PASSWORD=<your-password>

Replace the placeholders with your actual values:

PlaceholderDescription
<your-mysql-endpoint>The MySQL-compatible endpoint for LindormTable. See View connection addresses.
<your-username>Your LindormTable username.
<your-password>Your LindormTable password. To reset a forgotten password, see Manage users.

Choose the right endpoint for your deployment:

  • ECS instance (recommended): Use the virtual private cloud (VPC) endpoint for higher security and lower network latency. Set LINDORM_HOST to the MySQL-compatible VPC address.

  • Local machine: Enable a public endpoint first. In the Lindorm console, go to Database Connections > Wide Table Engine, then click Enable Public Endpoint. Set LINDORM_HOST to the MySQL-compatible Internet address.

Step 2: Create a connection and run a query

The following example creates a connection to LindormTable and runs a SHOW DATABASES query:

var mysql = require('mysql2');

var connection = mysql.createConnection({
    // The MySQL-compatible endpoint for LindormTable
    host: process.env.LINDORM_HOST,
    // The port for the MySQL protocol. Fixed value: 33060.
    port: 33060,
    // Your LindormTable username
    user: process.env.LINDORM_USER,
    // Your LindormTable password
    password: process.env.LINDORM_PASSWORD,
    // The database to connect to. Default: 'default'
    database: 'default',
    // Connection timeout in milliseconds. Default: 10000.
    connectTimeout: 10000
});

connection.connect(function(err) {
    if (err) {
        throw err;
    }
    console.log("Connection established.");

    connection.query('show databases', function(err1, results, fields) {
        if (err1) {
            throw err1;
        }
        console.log(fields);
        console.log(results);
    });

    connection.end(function(err2) {
        if (err2) {
            throw err2;
        }
        console.log("Connection closed.");
    });
});

Connection parameters:

ParameterDescriptionDefault
hostThe MySQL-compatible endpoint for LindormTable.
portThe port for the MySQL protocol. Fixed value: 33060.33060
userYour LindormTable username.
passwordYour LindormTable password.
databaseThe database to connect to.default
connectTimeoutThe connection timeout period, in milliseconds.10000

Step 3: Verify the connection

If the connection succeeds and your instance contains only the default database, the output is:

Connection established.
Connection closed.
[ `DATABASE` VARCHAR(0) ]
[ { DATABASE: 'default' }, { DATABASE: 'information_schema' } ]
Note

Even when only the default database exists, the query returns two rows: default and information_schema.

What's next