# mysqldriver

> ## Sample usage

Latest version **5.0.4** (published 2022-10-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install mysqldriver
pnpm add mysqldriver
yarn add mysqldriver
bun add mysqldriver
```

Provides the command `mysqldriver`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.4 |
| Published | 2022-10-05 |
| First published | 2018-11-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 356.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | conradkoh |

## Links

- npm: https://www.npmjs.com/package/mysqldriver
- Repository: https://github.com/conradkoh/mysqldriver
- Homepage: https://github.com/conradkoh/mysqldriver#readme
- Issues: https://github.com/conradkoh/mysqldriver/issues
- npm.io page: https://npm.io/package/mysqldriver

## Dependencies (10)

- [chai](https://npm.io/package/chai.md) ^4.2.0
- [knex](https://npm.io/package/knex.md) ^2.3.0
- [uuid](https://npm.io/package/uuid.md) ^3.4.0
- [dayjs](https://npm.io/package/dayjs.md) ^1.10.5
- [mocha](https://npm.io/package/mocha.md) ^8.1.1
- [mysql](https://npm.io/package/mysql.md) ^2.18.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^1.0.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [ts-mocha](https://npm.io/package/ts-mocha.md) ^7.0.0
- [serverless-mysql](https://npm.io/package/serverless-mysql.md) ^1.5.4

## Recent versions

- 5.0.4 (latest) — 2022-10-05
- 5.0.3 — 2022-10-05
- 5.0.2 — 2022-10-05
- 5.0.1 — 2022-10-05
- 5.0.0 — 2022-02-19
- 4.4.1 — 2022-02-05
- 4.4.0 — 2021-06-30
- 4.3.11 — 2021-02-21
- 4.3.10 — 2021-02-21
- 4.3.9 — 2021-02-21
- 4.3.8 — 2021-02-21
- 4.3.7 — 2020-11-24
- 4.3.6 — 2020-11-02
- 3.0.23 — 2020-11-01
- 4.3.5 — 2020-11-01
- … 50 more at https://npm.io/package/mysqldriver/versions

## README

# MySQLDriver

## Sample usage

```javascript
const MySQLDriver = require('mysqldriver');
const config = {
  host: '127.0.0.1',
  user: 'admin',
  password: 'password',
  database: 'mydatabase',
  port: 3306,
};
const DB = MySQLDriver.connect(config);
const users = await DB.getRecords('user', { name: 'John Doe' }); // Gets all records who have name John Doe
```

## Setting up the test database

Execute the following statements

```sql
CREATE DATABASE mysqldriver_test;
CREATE USER 'testuser'@'%' IDENTIFIED WITH mysql_native_password BY 'P@ssw0rd';
GRANT ALL PRIVILEGES ON mysqldriver_test.* TO 'testuser'@'%';
FLUSH PRIVILEGES;
```

Create a configuration file `dbconfig.js`

```javascript
const config = {
  host: '127.0.0.1',
  database: 'mysqldriver_test',
  password: 'P@ssw0rd',
  user: 'testuser',
};
module.exports = config;
```

## Migrations

Create a new migration

```
DB_HOST=127.0.0.1 DB_DATABASE=mysqldriver_test DB_USERNAME=testuser DB_PASSWORD=P@ssw0rd mysqldriver create-migration --name createNewTable
```

Apply migrations

```
DB_HOST=127.0.0.1 DB_DATABASE=mysqldriver_test DB_USERNAME=testuser DB_PASSWORD=P@ssw0rd mysqldriver migrate --count 500
```

Rollback a migration

```
DB_HOST=127.0.0.1 DB_DATABASE=mysqldriver_test DB_USERNAME=testuser DB_PASSWORD=P@ssw0rd mysqldriver rollback --count 500
```

Migration options

```bash
DB_HOST= # The database host
DB_DATABASE= # The database to connect to
DB_USERNAME= #The database user's username
DB_PASSWORD= #The password for the database user
DB_PORT= #The port to connect to
DB_SSL_CA_CERTIFICATE # The base64 encoded string for the CA certificate
DB_REQUIRE_SSL= # Whether to enforce that the connection requires an ssl connection (1 or 0, defaults to 1 if cetificate is provided)
DB_SSL_ALLOW_SELF_SIGNED_CERT= # Whether self-signed certificates are allowed (1 or 0, defaults to 0)

```

---
_Source: https://npm.io/package/mysqldriver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
