Mysql连接,一个还是多个? [英] Mysql Connection, one or many?

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

问题描述

我正在用python编写脚本,该脚本基本上查询WMI并更新mysql数据库中的信息.其中一种写一些你需要的东西"以学习编程练习.

I'm writing a script in python which basically queries WMI and updates the information in a mysql database. One of those "write something you need" to learn to program exercises.

例如,如果脚本中间出现中断,则远程计算机将关闭,它会分成多个功能.

In case something breaks in the middle of the script, for example, the remote computer turns off, it's separated out into functions.

查询一些WMI数据
将其更新到数据库
查询其他WMI数据
将其更新到数据库

Query Some WMI data
Update that to the database
Query Other WMI data
Update that to the database

最好在开始时打开一个mysql连接,然后在每次更新后使其保持打开状态或关闭连接吗?

Is it better to open one mysql connection at the beginning and leave it open or close the connection after each update?

似乎一个连接将使用较少的资源. (尽管我只是在学习,所以这是一个完整的猜测.)但是,打开和关闭每个更新的连接似乎更加整洁".函数将更加独立,而不是依赖于该函数之外的代码.

It seems as though one connection would use less resources. (Although I'm just learning, so this is a complete guess.) However, opening and closing the connection with each update seems more 'neat'. Functions would be more stand alone, rather than depend on code outside that function.

推荐答案

但是,打开和关闭每次更新的连接似乎更加简洁"."

"However, opening and closing the connection with each update seems more 'neat'. "

这也是一笔巨大的开销-并没有实际的好处.

It's also a huge amount of overhead -- and there's no actual benefit.

创建和处理连接相对昂贵.更重要的是,真正的原因是什么?它如何改进,简化和阐明?

Creating and disposing of connections is relatively expensive. More importantly, what's the actual reason? How does it improve, simplify, clarify?

通常,从启动到停止,大多数应用程序都使用一种连接.

Generally, most applications have one connection that they use from when they start to when they stop.

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

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