连接到 mySQL

发布于 2024-07-29 06:21:40 字数 388 浏览 3 评论 0原文

我使用的一个 ERP 应用程序的配置方式是只有 1 个用户(例如 USER A)连接到数据库。 任何登录到系统并尝试执行任何操作的应用程序用户(员工数以千计)实际上都是在调用 USER A 连接到数据库并为他执行查询。 数据库是Oracle。

我想知道如何用 mySQL 实现类似的事情。 我有一个使用 php 和 mySQL 数据库构建的 Web 应用程序。 我希望不同的人通过网络查询数据库。 目前,当用户打开网页时,通过单个 db 用户建立与数据库的连接。 在查询结束时,我关闭连接。 然而,数据库的最大用户连接数为 10,这在我看来意味着一个用户最多只能建立 10 个连接。 我不想为所有尝试使用我的应用程序的人创建多个用户(我什至不知道将使用该应用程序的人数,并且我不相信这将是一个可扩展的解决方案)

One of the ERP applications I worked with was configured in such a way that there was only 1 user (for example USER A) who connected to the database. Any user of the application (workforce was in the thousands) who logged on to the system and tried to do anything was in effect calling USER A to connect to the database and execute queries for him. The database was Oracle.

I was wondering how to achieve a similar thing with mySQL. I have a web application built with php and mySQL database. I expect different people to query the database via the web. Currently when a user opens up the web page, a connection to the database is made via a single db user. At the end of the query, I close the connection. However the database has a maximum user connection of 10 which in my understanding means one user can only establish a max of 10 connections. I do not want to have to create several users for all the people who try to use my application (I do not even know the number of people who will use the application and I do not believe this will be a scalable solution)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新一帅帅 2024-08-05 06:21:40

您应该寻找数据库连接缓存机制作为您的 Web 服务器或编程语言的组件。 这种机制将为您透明地重用连接。

You should look for a db connection caching mechanism as a component for either your web server or your programming language. Such a mechanism will reuse connections transparently for you.

怕倦 2024-08-05 06:21:40

如果数据库连接被拒绝,则返回 HTTP 错误 502。如果连接在每个页面加载结束时关闭,它们应该只会持续约 100 毫秒,因此在大多数情况下并发连接数会很低。

如果您需要调整它,请编辑 my.cnf 以增加并发连接:

max_connections = 150
max_user_connections = 150

如果流量非常高,您可以在 PHP 中启用持久 MySQL 连接,或缓存您的内容,以免损坏数据库。

希望有帮助!

If the database connection is refused return HTTP error 502. If connections are closed at the end of each pageload they should only last ~100ms, so concurrent connections will be low for most situations.

Should you need to adjust it, edit my.cnf to increase concurrent connections:

max_connections = 150
max_user_connections = 150

If traffic is very high you can enable persistent MySQL connections in PHP, or cache your content so not to hammer the database.

Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文