{"id":43380,"library":"mysql8","title":"mysql8 (Fork of mysqljs/mysql for MySQL 8)","description":"A community fork of the official mysqljs/mysql package (v2.17.3) to ensure compatibility with MySQL 8 authentication and features. This package provides a pure JavaScript, no-compile MySQL driver for Node.js (>=0.6). It offers connection pooling, prepared statements, streaming, and transaction support. It is an active drop-in replacement for the original mysql package, which has been in maintenance mode. Note that the original mysql package is no longer actively maintained; the mysql8 fork addresses issues like caching_sha2_password support. However, for new projects, the mysql2 package is recommended due to better performance, promise support, and ongoing maintenance.","status":"active","version":"2.17.3","language":"javascript","source_language":"en","source_url":"https://github.com/mysqljs/mysql","tags":["javascript"],"install":[{"cmd":"npm install mysql8","lang":"bash","label":"npm"},{"cmd":"yarn add mysql8","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql8","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import, ESM syntax. Use 'mysql8' as the package name, not 'mysql'.","wrong":"import mysql from 'mysql'","symbol":"mysql","correct":"import mysql from 'mysql8'"},{"note":"CommonJS require(). createConnection is a method on the default export, not a named export.","wrong":"const { createConnection } = require('mysql8');","symbol":"createConnection","correct":"const mysql = require('mysql8');\nconst connection = mysql.createConnection({...})"},{"note":"Same as createConnection: it's a method on the default mysql object.","wrong":"import { createPool } from 'mysql8';","symbol":"createPool","correct":"import mysql from 'mysql8';\nconst pool = mysql.createPool({...});"}],"quickstart":{"code":"import mysql from 'mysql8';\n\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'root',\n  password: process.env.DB_PASSWORD ?? '',\n  database: 'test'\n});\n\nconnection.connect((err) => {\n  if (err) {\n    console.error('Error connecting: ' + err.stack);\n    return;\n  }\n  console.log('Connected as id ' + connection.threadId);\n});\n\nconnection.query('SELECT 1 + 1 AS solution', (error, results, fields) => {\n  if (error) throw error;\n  console.log('The solution is: ', results[0].solution);\n});\n\nconnection.end();","lang":"javascript","description":"Connects to MySQL, runs a query, and logs the result. Uses ESM import and environment variable for password."},"warnings":[{"fix":"Use the mysql2 package or wrap callbacks with util.promisify.","message":"The mysql package (and its forks) use callback-based APIs. Promises are not natively supported. Use util.promisify or wrap in a Promise manually.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use `import mysql from 'mysql8'` or `const mysql = require('mysql8')`.","message":"The package name is 'mysql8', but the code and documentation often refer to 'mysql'. Ensure you import from 'mysql8' and not 'mysql'.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"If using TypeScript, set `esModuleInterop: true` in tsconfig.json or use `import * as mysql from 'mysql8'`.","message":"The underlying `mysql` package (and this fork) have not adopted ES modules properly; the package does not have an 'exports' field. Using `import mysql from 'mysql8'` may require `esModuleInterop` or a default import workaround in TypeScript.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Add `authSwitchHandler: function ({pluginName, pluginData}, cb) { ... }` to connection options, or alter MySQL user to use `mysql_native_password`.","message":"MySQL 8's default authentication plugin is `caching_sha2_password`. This fork may not handle it correctly; you may need to set `defaultAuthenticationPlugin` or `authSwitchHandler`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'0.6':39 '8':7,22 'activ':53,78 'address':83 'authent':23 'better':101 'cach':86 'communiti':9 'compat':19 'compil':34 'connect':42 'driver':36 'drop':55 'drop-in':54 'due':99 'ensur':18 'featur':25 'fork':2,10,82 'howev':90 'issu':84 'javascript':31,108 'like':85 'longer':77 'maintain':79 'mainten':67,107 'mode':68 'mysql':6,21,35,61,73 'mysql2':95 'mysql8':1,81 'mysqljs/mysql':4,14 'new':92 'no-compil':32 'node.js':38 'note':69 'offer':41 'offici':13 'ongo':106 'origin':60,72 'packag':15,27,62,74,96 'password':88 'perform':102 'pool':43 'prepar':44 'project':93 'promis':103 'provid':28 'pure':30 'recommend':98 'replac':57 'sha2':87 'statement':45 'stream':46 'support':49,89,104 'transact':48 'v2.17.3':16","created_at":"2026-06-05T16:59:31.688925+00:00","updated_at":"2026-06-05T16:59:31.688925+00:00","problems":[{"fix":"Change the user's authentication plugin: ALTER USER 'user'@'host' IDENTIFIED WITH mysql_native_password BY 'password';","cause":"MySQL 8 default authentication plugin caching_sha2_password is not supported by this driver.","error":"Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client"},{"fix":"Use `const mysql = require('mysql8')` or `import mysql from 'mysql8'`.","cause":"Incorrect import: using named import instead of default import.","error":"TypeError: mysql.createConnection is not a function"},{"fix":"Ensure connection options are correct and call `connection.connect()` before `connection.query()`.","cause":"Connection not established properly; missing call to `.connect()` or error in connection options.","error":"TypeError: Cannot read properties of undefined (reading 'query')"}],"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/mysqljs/mysql#readme","github":"https://github.com/mysqljs/mysql","docs":null,"changelog":null,"pypi":null,"npm":"mysql8","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}}