Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

What is the difference between MySQL & MySQL2 considering NodeJS

Writer Matthew Barrera

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:

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?

4 Answers

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:

4

Extract from

"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

3

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 dependencyconnection.query(sql,(err,res)=>{*some fn here*}) returns all the rows including the success outcomes of a query. Whereas mysql2 dependencyconnection.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);

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy