{"id":42596,"library":"db-migrate-mysql2","title":"db-migrate mysql2 driver","description":"A database driver for db-migrate that uses mysql2 instead of the deprecated mysql module. Version 1.0.0 is the current stable release, with occasional updates. It provides a drop-in replacement for the original db-migrate mysql driver, supporting modern MySQL features like prepared statements, async/await, and promises through mysql2. Unlike the original mysql driver, this version is actively maintained and compatible with MySQL 8+. It is ideal for projects that need reliable database migrations in Node.js with MySQL.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jessebye/db-migrate-mysql","tags":["javascript","db-migrate","db","database","migrate","migration","driver"],"install":[{"cmd":"npm install db-migrate-mysql2","lang":"bash","label":"npm"},{"cmd":"yarn add db-migrate-mysql2","lang":"bash","label":"yarn"},{"cmd":"pnpm add db-migrate-mysql2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"required by db-migrate to load driver plugins","package":"db-migrate-base","optional":false},{"reason":"actual MySQL connection and query execution","package":"mysql2","optional":false}],"imports":[{"note":"Do not require the driver directly. Use db-migrate API with driver field set to 'mysql2'.","wrong":"const driver = require('db-migrate-mysql2');","symbol":"default (driver)","correct":"const dbmigrate = require('db-migrate');\nconst driver = dbmigrate.getInstance({ driver: 'mysql2' });"},{"note":"Always use getInstance() with the driver option. Do not use constructor.","wrong":"const DBMigrate = require('db-migrate');\nconst instance = new DBMigrate({ driver: 'mysql2' });","symbol":"driver instance with options","correct":"const dbmigrate = require('db-migrate');\nconst instance = dbmigrate.getInstance(true, { driver: 'mysql2', config: { host: 'localhost', user: 'root', password: '', database: 'test' } });"},{"note":"This package doesn't export runtime symbols; only types are available if using TypeScript.","wrong":"import { Driver } from 'db-migrate-mysql2';","symbol":"type imports (TypeScript)","correct":"import type { Driver } from 'db-migrate-mysql2';"}],"quickstart":{"code":"// Install: npm install db-migrate db-migrate-mysql2\n// database.json\n{\n  \"dev\": {\n    \"driver\": \"mysql2\",\n    \"user\": \"root\",\n    \"password\": \"\",\n    \"host\": \"localhost\",\n    \"database\": \"myapp_dev\"\n  }\n}\n\n// Run migration:\n// npx db-migrate up\n\n// Programmatic usage:\nconst dbmigrate = require('db-migrate');\nconst instance = dbmigrate.getInstance(true, {\n  driver: 'mysql2',\n  config: {\n    host: 'localhost',\n    user: 'root',\n    password: '',\n    database: 'myapp_dev'\n  }\n});\n\n// Create migration file with up and down functions\n// Up: create table\n// Down: drop table\ninstance.create('add-users-table', (err, migration) => {\n  if (err) throw err;\n  console.log('Created:', migration.name);\n});","lang":"javascript","description":"Shows how to install, configure, and run a migration using db-migrate with the mysql2 driver."},"warnings":[{"fix":"Set driver to 'mysql2' in database.json or programmatic config.","message":"The driver name must be exactly 'mysql2' in the configuration, but the original db-migrate mysql driver uses 'mysql'. Mixing them up will cause a 'No such driver' error.","severity":"gotcha","affected_versions":"all"},{"fix":"Switch to 'db-migrate-mysql2' and set driver to 'mysql2' in config.","message":"The original 'mysql' driver is deprecated and may stop working. This package is the recommended replacement for MySQL.","severity":"deprecated","affected_versions":"all"},{"fix":"npm uninstall db-migrate-mysql","message":"If you have both 'db-migrate-mysql' and 'db-migrate-mysql2' installed, db-migrate may load the wrong driver. Uninstall the old driver to avoid conflicts.","severity":"gotcha","affected_versions":"all"},{"fix":"Use async migration functions: async function up(db) { await db.runSql('...'); }","message":"Version 1.0.0 uses mysql2's callback API by default, but promises are available via mysql2's promise API. Ensure your migration functions handle callbacks correctly or use async/await with the promise wrapper.","severity":"breaking","affected_versions":"1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':23 '8':73 'activ':67 'async/await':54 'compat':70 'current':26 'databas':7,82,93 'db':2,11,43,90,92 'db-migrat':1,10,42,89 'deprec':19 'driver':5,8,46,63,96 'drop':36 'drop-in':35 'featur':50 'ideal':76 'instead':16 'javascript':88 'like':51 'maintain':68 'migrat':3,12,44,83,91,94,95 'modern':48 'modul':21 'mysql':20,45,49,62,72,87 'mysql2':4,15,58 'need':80 'node.js':85 'occasion':30 'origin':41,61 'prepar':52 'project':78 'promis':56 'provid':33 'releas':28 'reliabl':81 'replac':38 'stabl':27 'statement':53 'support':47 'unlik':59 'updat':31 'use':14 'version':22,65","created_at":"2026-06-05T16:55:44.505125+00:00","updated_at":"2026-06-05T16:55:44.505125+00:00","problems":[{"fix":"Install db-migrate-mysql2 and set driver: 'mysql2' in database.json","cause":"Using driver name 'mysql' instead of 'mysql2' in config, or driver package not installed.","error":"Error: No such driver found. Add it by installing db-migrate-<driver>"},{"fix":"Update database.json with correct user, password, host, and database.","cause":"Missing or incorrect credentials in database configuration.","error":"Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)"},{"fix":"Ensure db-migrate version >= 0.11.0 and use const dbmigrate = require('db-migrate'); then call dbmigrate.getInstance()","cause":"Using an older version of db-migrate that doesn't export getInstance, or incorrect import style.","error":"TypeError: dbmigrate.getInstance is not a function"},{"fix":"Run: npm install db-migrate-base","cause":"Missing peer dependency or incorrect npm install (npm < 7 auto-installs peers).","error":"Error: Cannot find module 'db-migrate-base'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jessebye/db-migrate-mysql","github":"https://github.com/jessebye/db-migrate-mysql","docs":null,"changelog":null,"pypi":null,"npm":"db-migrate-mysql2","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}