MySQL:单连接还是多连接? [英] MySQL: Single or Multiple Connections?

查看:166
本文介绍了MySQL:单连接还是多连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个服务器应用程序,它使用mysql进行一些数据存储。我应该在服务器的启动时创建一个连接到mysql,并将其用于所有查询,或者在每个查询上创建连接?哪个更好/更快?

I am developing a server application, which uses mysql for some data storing. Should I create a connection to the mysql on the server's start and use it for all queries, or create connection on each query? Which is better/faster?

推荐答案

如果你问我,最好只使用一个连接,变量没有任何问题。此外,使用静态变量,很容易将连接永久保存在脚本中的某处。

If you ask me, It's better to use only one connection, that way you can use session variables without any issues. Besides, with static variables, it's easy to permanently save the connection somewhere in the script.

这篇关于MySQL:单连接还是多连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆