<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 的自动重新连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
                  MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
                  Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
                  How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
                  Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
                  Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)

                        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>