MariaDB Connector/Node.js when Connecting to Local Databases

MariaDB Connector/Node.js is a native Javascript driver.

The required files can be downloaded from:
https://mariadb.com/downloads/connector
The source code is available on GitHub:
https://github.com/MariaDB/mariadb-connector-nodejs
MariaDB Connector/Node.js on npm, the package manager for JavaScript:
https://www.npmjs.com/package/mariadb



Installing the Driver The driver can be installed using npm: npm install mariadb

See promise documentation for detailed API.
Callback documentation describe the callback wrapper for compatibility with existing drivers.

Connecting to Local Databases:

When working with a local database (that is, cases where MariaDB and your Node.js application run on the same host), you can connect to MariaDB through the Unix socket or Windows named pipe for better performance, rather than using the TCP/IP layer.

In order to set this up, you need to assign the connection a socketPath value. When this is done, the Connector ignores the host and port options.

The specific socket path you need to set is defined by the socket server system variable. If you don't know it off hand, you can retrieve it from the server.
SHOW VARIABLES LIKE 'socket';

Note: need config in "my.ini":

Example: C:\Program Files\MariaDB 10.5\data\my.ini:
[mysqld]
named-pipe
datadir=C:/Program Files/MariaDB 10.5/data
port=3306
innodb_buffer_pool_size=127M
character-set-server=utf8
[client]
port=3306
plugin-dir=C:/Program Files/MariaDB 10.5/lib/plugin

Creat Pool Connect:


const mariadb = require('mariadb');
const pool= mariadb.createPool({
    socketPath: '\\\\.\\pipe\\MySQL',// '/var/lib/mysql/mysql.sock' on Unix-like operating systems
    user: 'root',
    password: 'pass12345',
    // connectionLimit: 5
});

Comments