考虑到 NodeJS,MySQL 和 MySQL2 之间有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25344661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:58:58  来源:igfitidea点击:

What is the difference between MySQL & MySQL2 considering NodeJS

mysqlnode.jsrelational-databasemysql2

提问by Eric Bishard

So I have read the following post"

所以我已经阅读了以下帖子”

What the difference between mysql and mysql2 gem

mysql 和 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:

到目前为止,我只将 MongoDB 与 NodeJS 一起使用,我希望能够学习 MySQL 来满足我的任何关系数据库需求。在研究 MySQL 和 NodeJS 时,我找到了 MySQL2 的存储库,它似乎与 MySQL 网站没有任何关系,我假设已经创建了 API,可以更快地使用 NodeJS 和 Ruby 等语言进行开发。从 NodeJS 的角度来看,我假设我仍然在我的服务器上运行常规的 MySQL 数据库,但我需要使用这些新的 API 与它进行交互,例如:

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

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

我还看到一个网站,他们在那里进行性能基准测试,而 NodeJS 和 MySQL 的性能非常低。和 NodeJS & MySQL2 非常高

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

此信息的来源: 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?

问题:我是简单地在我的服务器上使用常规 MySQL 数据库并使用这个 mysql2 API 还是有一个不同的 MySQL 实现可以与这个 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?

我已经有大约 10 年没有使用 MySQL 了。我只用过微软的 SQL Server。所以我严重落后。我已经开始使用 NodeJS 并认为我最好的关系数据库选项是 MySQL,还有什么我应该寻找的吗?

采纳答案by monkeyinsight

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.

这只是普通人编写的 2 个不同的 API。不同之处在于命令的语法和性能,只需安装两者,针对您的目标进行自己的测试,然后选择您认为更适合您的一个。

Here is a comparison by NPMCompare:

这是NPMCompare比较

回答by Antonio Garcia Marin

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

摘自https://www.npmjs.com/package/mysql2

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

“MySQL2 大部分 API 与 mysqljs 兼容并支持大多数功能。MySQL2 还提供这些附加功能

  • 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"
  • 更快/更好的性能
  • 准备好的报表
  • MySQL 二进制日志协议
  • MySQL服务器
  • 对编码和整理的扩展支持
  • 承诺包装
  • 压缩
  • SSL 和身份验证开关
  • 自定义流
  • 汇集”

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

只有前两个功能更好:更快更安全

回答by Eric Moore

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.

如果您查看图中用于 mysql 和 mysql2 的源代码,他将同时使用 mysql api。唯一的区别是他每次都关闭连接的那个标记为 mysql 的人。所以外卖是不要每次都关闭连接。mysql2 api 应该更快,但我还没有看到任何数据。

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

有用于图形数据的“mysql2”代码。注意 api 仍然是 mysql 而不是 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);