What is the difference between MySQL & MySQL2 considering NodeJS

Mysqlnode.jsRelational DatabaseMysql2

Mysql Problem Overview


So I have read the following post"

What the difference between mysql and mysql2 gem

So far I have only used MongoDB with NodeJS and I want to be able to learn MySQL for any of my relational database needs. While researching MySQL & NodeJS I have found repositories for MySQL2 and it appears to have nothing in relation to the MySQL website, I'm assuming that there have been API's created that make it faster for developing with languages like NodeJS & Ruby. From a NodeJS standpoint, I'm assuming that I still run the regular MySQL database o my server, but I need to interact with it using these new API's like:

https://github.com/sidorares/node-mysql2/blob/master/README.md

I have also seen a site where they do performance benchmarks and NodeJS & MySQL come in very low for performance. and NodeJS & MySQL2 very High

Source for this info: php-nodejs-mysql-and-mongo

Image from this post:

enter image description here

Question: Do I simply use the regular MySQL database on my server and use this mysql2 API or is there a different implementation of MySQL that works with this API?

I have not used MySQL in about 10 years. I have only Used Microsoft's SQL Server. So I'm severely behind. I have started using NodeJS and figured that my best relational database options were MySQL, Is there something else I should look for?

Mysql Solutions


Solution 1 - Mysql

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:

Solution 2 - Mysql

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

Solution 3 - Mysql

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.

Solution 4 - Mysql

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);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric BishardView Question on Stackoverflow
Solution 1 - MysqlmonkeyinsightView Answer on Stackoverflow
Solution 2 - MysqlAntonio Garcia MarinView Answer on Stackoverflow
Solution 3 - MysqlSrinath KamathView Answer on Stackoverflow
Solution 4 - MysqlEric MooreView Answer on Stackoverflow