Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report

mysql2 3.7.1

fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS
Package summary
Share
0
issues
0
licenses
Package created
17 Apr 2013
Version published
17 Jan 2024
Maintainers
3
Total deps
0
Direct deps
0
License
MIT
Generating a report...
Hold on while we generate a fresh audit report for this package.

Frequently Asked Questions

What does mysql2 do?

MySQL2 is a robust MySQL client for Node.js, putting an exclusive focus on performance. It supports features such as prepared statements, non-UTF8 encodings, binary log protocol, data compression, and SSL among others. MySQL2 is free from native bindings, meaning it can be smoothly installed on Linux, Mac OS, or Windows without any issues.

How do you use mysql2?

To use MySQL2, you first need to install it by running the command npm install --save mysql2. Once installed, you can start incorporating it in your code as follows:

// importing the client
const mysql = require('mysql2');

// creating a connection to your database
const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  database: 'test'
});

// executing a simple query
connection.query(
  'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45',
  function(err, results, fields) {
    console.log(results); // returns rows provided by the server
    console.log(fields); // contains extra meta data about results, if available
  }
);

// executing a query with a placeholder
connection.query(
  'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
  ['Page', 45],
  function(err, results) {
    console.log(results);
  }
);

For more advanced usages such as using prepared statements, connection pools, Promise wrapper, and more, refer to the code provided in the readme.

Where are the mysql2 docs?

The MySQL2 documentation can be found directly here in the GitHub repository. It provides comprehensive insights on how to use the package, including a multitude of code examples for understanding advanced concepts. Also, the readme provides a precise overview of the package, starting from installation and basic usage, to more advanced topics. For TypeScript users, there's also a separate TypeScript documentation with relevant code examples.