Skip to main content
Version: v7 - alpha

Sequelize for MariaDB

Version Compatibility

See Releases to see which versions of MariaDB are supported.

To use Sequelize with MariaDB, you need to install the @sequelize/mariadb dialect package:

npm i @sequelize/mariadb

Then use the MariaDbDialect class as the dialect option in the Sequelize constructor:

import { Sequelize } from '@sequelize/core';
import { MariaDbDialect } from '@sequelize/mariadb';

const sequelize = new Sequelize({
dialect: MariaDbDialect,
database: 'mydb',
user: 'myuser',
password: 'mypass',
host: 'localhost',
port: 3306,
showWarnings: true,
connectTimeout: 1000,
});

Connection Options

Connection Options are used to configure a connection to the database.

The simplest way to use them is at the root of the configuration object. These options can also be used in the replication option to customize the connection for each replica, and can be modified by the beforeConnect hook on a connection-by-connection basis.

The following options are passed as-is to the mariadb package that Sequelize uses to connect to MariaDB. Please refer to the MariaDB documentation for more information about what each of these options do.

For convenience, here is an edited copy of the documentation that only includes the options that are accepted by Sequelize:

OptionDescriptionTypeDefault
userUser to access databasestring
passwordUser passwordstring
hostIP address or DNS of database server. Not used when using the socketPath optionstring"localhost"
portDatabase server port numberinteger3306
databaseDefault database to use when establishing the connectionstring
socketPathPermit connecting to the database via Unix domain socket or named pipe, if the server allows itstring
compressCompress exchanges with database using gzip. This can give you better performance when accessing a database in a different location.booleanfalse
connectTimeoutConnection timeout in millisecondsinteger1000
socketTimeoutSocket timeout in milliseconds after the connection is establishedinteger0
maxAllowedPacketpermit to indicate server global variable max_allowed_packet value to ensure efficient batching. default is 4Mb. see batch documentationinteger4196304
prepareCacheLengthDefine prepare LRU cache length. 0 means no cacheint256
sslSSL options. See SSL options in the MariaDB documentationboolean | objectfalse
charsetProtocol character set used with the server. Connection collation will be the default collation associated with charset. It's mainly used for micro-optimizations. The default is often sufficient.stringUTF8MB4
collation(used in replacement of charset) Permit to defined collation used for connection. This will defined the charset encoding used for exchanges with database and defines the order used when comparing strings. It's mainly used for micro-optimizationsstringUTF8MB4_UNICODE_CI
debugLogs all exchanges with the server. Displays in hexa.booleanfalse
debugLenString length of logged message / error or traceinteger256
logParamindicate if parameters must be logged by query logger.booleanfalse
foundRowsWhen enabled, the update number corresponds to update rows. When disabled, it indicates the real rows changed.booleantrue
multipleStatementsAllows you to issue several SQL statements in a single query() call. (That is, INSERT INTO a VALUES('b'); INSERT INTO c VALUES('d');).

This may be a security risk as it allows for SQL Injection attacks.
booleanfalse
permitLocalInfileAllows the use of LOAD DATA INFILE statements.

Loading data from a file from the client may be a security issue, as a man-in-the-middle proxy server can change the actual file the server loads. Being able to execute a query on the client gives you access to files on the client.
booleanfalse
pipeliningSends queries one by one without waiting on the results of the previous entry. For more information, see Pipelining(booleantrue
traceAdds the stack trace at the time of query creation to the error stack trace, making it easier to identify the part of the code that issued the query. Note: This feature is disabled by default due to the performance cost of stack creation. Only turn it on when you need to debug issues.booleanfalse
connectAttributesSends information, (client name, version, operating system, Node.js version, and so on) to the Performance Schema. When enabled, the Connector sends JSON attributes in addition to the defaults.boolean | objectfalse
sessionVariablesPermit to set session variables when connecting. Example: sessionVariables: { idle_transaction_timeout: 10000 }object
initSqlWhen a connection is established, permit to execute commands before using connectionstringarray
bulkdisabled bulk command in batchboolean
forceVersionCheckForce server version check by explicitly using SELECT VERSION(), not relying on server initial packet.booleanfalse
checkDuplicateIndicate to throw an exception if result-set will not contain some data due to having duplicate identifier.
JSON cannot have multiple identical key, so query like SELECT 1 as i, 2 as i cannot result in { i:1, i:2 }, 'i:1' would be skipped.
When checkDuplicate is enable (default) driver will throw an error if some data are skipped.
booleantrue
keepAliveDelaypermit to enable socket keep alive, setting delay. 0 means not enabled. Keep in mind that this don't reset server @@wait_timeout (use pool option idleTimeout for that). in msinteger
rsaPublicKeyIndicate path/content to MySQL server RSA public key.string
cachingRsaPublicKeyIndicate path/content to MySQL server caching RSA public key.string
allowPublicKeyRetrievalIndicate that if rsaPublicKey or cachingRsaPublicKey public key are not provided, if client can ask server to send public key.booleanfalse
streampermits to set a function with parameter to set streamfunction
metaEnumerablemake resultset meta property enumerablebooleanfalse
infileStreamFactoryWhen LOAD LOCAL command executed, permit to set a callback function of type (filepath?: string) => stream.Readable. Connector will then not send file from LOAD LOCAL, but Readable content. This can permit to set extra validation of file path for example.function
logPacketsDebug option : permit to save last exchanged packet. Error messages will display those last exchanged packet.booleanfalse
debugCompressThis will print all incoming and outgoing compressed packets on stdout.booleanfalse
queryTimeoutCommand execution timeoutnumber

Other MariaDB Options

The following options are also available for MariaDB:

OptionDescription
showWarningsIf true, warnings produced during the execution of a query will be sent to the logging callback. Default is false.