What is the difference between MySQL & MySQL2 considering NodeJS

This is just 2 different APIs written by regular people. Difference is in syntax of commands and maybe in performance, just install both, make your own tests for your goals and choose one you think is more suitable for you.

Here is a comparison by NPMCompare:


Extract from https://www.npmjs.com/package/mysql2

"MySQL2 is mostly API compatible with mysqljs and supports majority of features. MySQL2 also offers these additional features

  • Faster / Better Performance
  • Prepared Statements
  • MySQL Binary Log Protocol
  • MySQL Server
  • Extended support for Encoding and Collation
  • Promise Wrapper
  • Compression
  • SSL and Authentication Switch
  • Custom Streams
  • Pooling"

Only for the first two features is better: Faster and Secure


I had a lot of problems implementing npm i mysql dependency in my project. First off, if you are following MVC architecture mysql becomes tedious when it comes to extract and send data between server and client. npm i mysql2 simplifies this process, like executing a query is as easy as this

for mysql dependency connection.query(sql,(err,res)=>{*some fn here*}) returns all the rows including the success outcomes of a query. Whereas mysql2 dependency connection.execute(sql) returns onl;y the results from the query and not the rows.


If you look at the source code used for mysql and mysql2 in the graph he is using the mysql api for both of them. The only difference is that the one labeled mysql he is closing the connection each time. So the takeaway is to not close the connection each time. mysql2 api is supposed to be faster, but I haven't seen any data for that.

There is the "mysql2" code that was used for the graph data. Notice the api is still mysql not mysql2:

var sys = require('sys'),
http = require('http'),
mysql = require('mysql')
client = null;

client = mysql.createClient({
          user: 'root',
          password: '',
});
client.query('USE mongo');

http.createServer(function(req, res) {
        client.query(
                  'SELECT * FROM basic WHERE id = '+Math.floor(Math.random()*100000),
                  function selectCb(err, results, fields) {
                    if (err) {
                      res.writeHead(200, {'Content-Type': 'text/html'});
                          res.write('Bad');
                          res.end();
                      throw err;
                    }

                    res.writeHead(200, {'Content-Type': 'text/html'});
                        res.write('Gooood');
                        res.end();
                  }
                );
}).listen(8080);