Skip to main content

Connection

For detailed PoolOptions, see the MySQL2 createPool examples.

URI

import { MySQL } from 'mysql2-orm';

const pool = new MySQL(
'mysql://username:password@hostname.psdb.cloud/database-name?ssl={"rejectUnauthorized":true}'
);

PoolOptions

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
host: '',
user: '',
database: '',
password: '',
// ...
});

URI from PoolOptions

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
uri: 'mysql://username:password@hostname.psdb.cloud/database-name?ssl={"rejectUnauthorized":true}',
// ...
});

Available Connection Methods

  • insert
  • select
  • update
  • delete
  • beginTransaction (adapted from MySQL2 and preserving its original usage)
  • commit (adapted from MySQL2 and preserving its original usage)
  • rollback (adapted from MySQL2 and preserving its original usage)
  • release (adapted from MySQL2 and preserving its original usage)
  • execute (original exposed MySQL2 method)
  • query (original exposed MySQL2 method)
info

MySQL2 ORM exposes only the execute and query methods from Pool.

If you need to use other methods (such as getConnection), please use the original MySQL2 instead.


Closing the Connection

// ...

await pool.end();