<bdo id='v0Vfe'></bdo><ul id='v0Vfe'></ul>

    <tfoot id='v0Vfe'></tfoot>
  • <i id='v0Vfe'><tr id='v0Vfe'><dt id='v0Vfe'><q id='v0Vfe'><span id='v0Vfe'><b id='v0Vfe'><form id='v0Vfe'><ins id='v0Vfe'></ins><ul id='v0Vfe'></ul><sub id='v0Vfe'></sub></form><legend id='v0Vfe'></legend><bdo id='v0Vfe'><pre id='v0Vfe'><center id='v0Vfe'></center></pre></bdo></b><th id='v0Vfe'></th></span></q></dt></tr></i><div id='v0Vfe'><tfoot id='v0Vfe'></tfoot><dl id='v0Vfe'><fieldset id='v0Vfe'></fieldset></dl></div>

      <legend id='v0Vfe'><style id='v0Vfe'><dir id='v0Vfe'><q id='v0Vfe'></q></dir></style></legend>

        <small id='v0Vfe'></small><noframes id='v0Vfe'>

      1. 如何启用 MySQL 客户端与 MySQLdb 的自动重新连接?

        How to enable MySQL client auto re-connect with MySQLdb?(如何启用 MySQL 客户端与 MySQLdb 的自动重新连接?)

        <small id='qrUBO'></small><noframes id='qrUBO'>

          <tbody id='qrUBO'></tbody>
          <bdo id='qrUBO'></bdo><ul id='qrUBO'></ul>
          <i id='qrUBO'><tr id='qrUBO'><dt id='qrUBO'><q id='qrUBO'><span id='qrUBO'><b id='qrUBO'><form id='qrUBO'><ins id='qrUBO'></ins><ul id='qrUBO'></ul><sub id='qrUBO'></sub></form><legend id='qrUBO'></legend><bdo id='qrUBO'><pre id='qrUBO'><center id='qrUBO'></center></pre></bdo></b><th id='qrUBO'></th></span></q></dt></tr></i><div id='qrUBO'><tfoot id='qrUBO'></tfoot><dl id='qrUBO'><fieldset id='qrUBO'></fieldset></dl></div>

          1. <legend id='qrUBO'><style id='qrUBO'><dir id='qrUBO'><q id='qrUBO'></q></dir></style></legend>

          2. <tfoot id='qrUBO'></tfoot>

                1. 本文介绍了如何启用 MySQL 客户端与 MySQLdb 的自动重新连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我发现了 PHP 的方法:

                  I came across PHP way of doing the trick:

                  my_bool reconnect = 1;
                  mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);
                  

                  但没有使用 MySQLdb (python-mysql).

                  but no luck with MySQLdb (python-mysql).

                  谁能给个提示?谢谢.

                  推荐答案

                  我通过创建一个包装 cursor.execute() 方法的函数解决了这个问题,因为这就是抛出 MySQLdb.OperationalError 异常.上面的另一个示例暗示是 conn.cursor() 方法引发了此异常.

                  I solved this problem by creating a function that wraps the cursor.execute() method since that's what was throwing the MySQLdb.OperationalError exception. The other example above implies that it is the conn.cursor() method that throws this exception.

                  import MySQLdb
                  
                  class DB:
                    conn = None
                  
                    def connect(self):
                      self.conn = MySQLdb.connect()
                  
                    def query(self, sql):
                      try:
                        cursor = self.conn.cursor()
                        cursor.execute(sql)
                      except (AttributeError, MySQLdb.OperationalError):
                        self.connect()
                        cursor = self.conn.cursor()
                        cursor.execute(sql)
                      return cursor
                  
                  db = DB()
                  sql = "SELECT * FROM foo"
                  cur = db.query(sql)
                  # wait a long time for the Mysql connection to timeout
                  cur = db.query(sql)
                  # still works
                  

                  这篇关于如何启用 MySQL 客户端与 MySQLdb 的自动重新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)

                        1. <small id='Hzkp1'></small><noframes id='Hzkp1'>

                            <bdo id='Hzkp1'></bdo><ul id='Hzkp1'></ul>

                            <tfoot id='Hzkp1'></tfoot>
                          • <i id='Hzkp1'><tr id='Hzkp1'><dt id='Hzkp1'><q id='Hzkp1'><span id='Hzkp1'><b id='Hzkp1'><form id='Hzkp1'><ins id='Hzkp1'></ins><ul id='Hzkp1'></ul><sub id='Hzkp1'></sub></form><legend id='Hzkp1'></legend><bdo id='Hzkp1'><pre id='Hzkp1'><center id='Hzkp1'></center></pre></bdo></b><th id='Hzkp1'></th></span></q></dt></tr></i><div id='Hzkp1'><tfoot id='Hzkp1'></tfoot><dl id='Hzkp1'><fieldset id='Hzkp1'></fieldset></dl></div>

                          • <legend id='Hzkp1'><style id='Hzkp1'><dir id='Hzkp1'><q id='Hzkp1'></q></dir></style></legend>
                              <tbody id='Hzkp1'></tbody>