在没有 node.js 的 javascript 服务器端连接到 MySQL

2023-10-09数据库问题
4

本文介绍了在没有 node.js 的 javascript 服务器端连接到 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 javascript 应用程序在像 nginxeclipse 本地服务器 这样的服务器上运行,我想知道是否可以将它与 mysql 服务器数据库连接.

I have a javascript application running with server like nginx or eclipse local server, and i would like to know if it is possible to connect it with mysql server database.

我知道它们是 nodejs 应用程序的很多 npm 包,但我不想使用 node js,因为如果我这样做,我有实现具有所有依赖项的 nodejs 应用程序的所有结构,我不太了解这项技术.

I know that they are a lot of npm packages for nodejs application, but i don't want to use node js because if i'll do that i have to implement all structure of nodejs application with all dependencies and i don't know very well this technology to do that.

谢谢.

推荐答案

没有办法直接从浏览器中运行的 JavaScript 连接到远程数据库服务器……如果有的话,可能会涉及一个巨大的安全漏洞,因为任何人有权访问客户端可以获取您的凭据并在服务器上运行他们喜欢的任何 SQL.您不太可能使您的数据库 GRANTS 足够细以供公众使用.

There is no way to connect to a remote database server directly from JavaScript running in a browser… and if there was it would probably involve a huge security hole since anyone with access to the client could take your credentials and run any SQL they like on the server. It is unlikely you could make your database GRANTS fine-grained enough for public consumption.

如果你想让你的客户端 JS 与你的数据库服务器交互,那么你需要为它编写一个 web 服务.您可以在 Node.JS 或您喜欢的任何其他服务器端环境中执行此操作.

If you want your client side JS to interact with your database server then you need to write a webservice for it. You can do that in Node.JS or any other server side environment you like.

如果您使用的是 Node.JS,那么您可能希望 Nginx 代理请求.

If you are using Node.JS then you will probably want Nginx to proxy the requests.

Nginx 支持 FastCGI 所以你可以写任何支持 FastCGI 的语言,例如 Perl 或 PHP.

Nginx supports FastCGI so you could write in any language that supports FastCGI such as Perl or PHP.

这篇关于在没有 node.js 的 javascript 服务器端连接到 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14