Skip to main content
Version: v7 - alpha

Sequelize for MySQL

Version Compatibility

See Releases to see which versions of MySQL are supported.

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

npm i @sequelize/mysql

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

import { Sequelize } from '@sequelize/core';
import { MySqlDialect } from '@sequelize/mysql';

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

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 mysql2 package that Sequelize uses to connect to MySQL. Please refer to the mysql2 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:

OptionDescription
databaseName of the database to use for this connection
userThe MySQL user to authenticate as
portThe port number to connect to. (Default: 3306)
hostThe hostname of the database you are connecting to. (Default: localhost)
localAddressThe source IP address to use for TCP connection
passwordThe password of that MySQL user
password1Alias for the MySQL user password. Makes a bit more sense in a multifactor authentication setup (see "password2" and "password3")
password22nd factor authentication password. Mandatory when the authentication policy for the MySQL user account requires an additional authentication method that needs a password. https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html
password33rd factor authentication password. Mandatory when the authentication policy for the MySQL user account requires two additional authentication methods and the last one needs a password. https://dev.mysql.com/doc/refman/8.0/en/multifactor-authentication.html
passwordSha1no documentation available
socketPathThe path to a unix domain socket to connect to. When used host and port are ignored.
sslobject with ssl parameters or a string containing name of ssl profile
charsetThe charset for the connection. This is called 'collation' in the SQL-level of MySQL (like utf8_general_ci). If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used. (Default: 'UTF8_GENERAL_CI')
compressno documentation available
traceGenerates stack traces on Error to include call site of library entrance ('long stack traces'). Slight performance penalty for most calls. (Default: true)
enableKeepAliveEnable keep-alive on the socket. (Default: true)
isServerno documentation available
insecureAuthAllow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
multipleStatementsAllow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)
waitForConnectionsno documentation available
connectionLimitno documentation available
connectTimeoutThe milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)
charsetNumberno documentation available
maxIdleno documentation available
queueLimitno documentation available
idleTimeoutno documentation available
maxPreparedStatementsno documentation available
keepAliveInitialDelayIf keep-alive is enabled users can supply an initial delay. (Default: 0)
infileStreamFactoryBy specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
flagsList of connection flags to use other than the default ones. It is also possible to denylist default ones
authSwitchHandlerno documentation available
connectAttributesno documentation available
authPluginsno documentation available
debugThis will print all incoming and outgoing packets on stdout. You can also restrict debugging to packet types by passing an array of types (strings) to debug;
streamno documentation available

Other MySQL Options

The following options are also available for MySQL:

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