Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

javascript - JavaScript可以与MySQL连接吗?(Can JavaScript connect with MySQL?)

Can JavaScript connect with MySQL?

(JavaScript可以与MySQL连接吗?)

If so, how?

(如果是这样,怎么办?)

  ask by Anonymous the Great translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Client-side JavaScript cannot access MySQL without some kind of bridge.

(如果没有某种桥接,客户端JavaScript将无法访问MySQL。)

But the above bold statements that JavaScript is just a client-side language are incorrect -- JavaScript can run client-side and server-side, as with Node.js.

(但是以上关于JavaScript只是一种客户端语言的粗体说法是错误的-JavaScript可以像Node.js一样在客户端和服务器端运行。)

Node.js can access MySQL through something like https://github.com/sidorares/node-mysql2

(Node.js可以通过https://github.com/sidorares/node-mysql2之类的东西访问MySQL)

You might also develop something using Socket.IO

(您还可以使用Socket.IO开发某些东西)

Did you mean to ask whether a client-side JS app can access MySQL?

(您是否要问客户端JS应用程序是否可以访问MySQL?)

I am not sure if such libraries exist, but they are possible.

(我不确定是否存在这样的库,但是它们是可能的。)

EDIT : Since writing, we now have MySQL Cluster :

(编辑 :自编写以来,我们现在有了MySQL Cluster :)

The MySQL Cluster JavaScript Driver for Node.js is just what it sounds like it is – it's a connector that can be called directly from your JavaScript code to read and write your data.

(听起来像Node.js的MySQL Cluster JavaScript驱动程序一样-它是一个连接器,可以直接从JavaScript代码中调用以读取和写入数据。)

As it accesses the data nodes directly, there is no extra latency from passing through a MySQL Server and need to convert from JavaScript code//objects into SQL operations.

(由于它直接访问数据节点,因此通过MySQL服务器不会产生额外的延迟,并且无需将JavaScript代码//对象转换为SQL操作。)

If for some reason, you'd prefer it to pass through a MySQL Server (for example if you're storing tables in InnoDB) then that can be configured.

(如果由于某种原因,您希望它通过MySQL服务器(例如,如果您将表存储在InnoDB中),则可以对其进行配置。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...