MySQLdb如何判断数据库连接有效?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

MySQLdb如何判断数据库连接有效?

kun xu-3
做了一个程序,用到MySQLdb,这个程序需要一直保持对数据库的连接,没有在文档中看到如何判断当前数据库链接有效的函数?
有没有用过的兄弟给个提示。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: MySQLdb如何判断数据库连接有效?

luo roger
用数据库连接池Dbutils,好像可以自动重连的。

在08-1-15,kun xu <[hidden email]> 写道:
做了一个程序,用到MySQLdb,这个程序需要一直保持对数据库的连接,没有在文档中看到如何判断当前数据库链接有效的函数?
有没有用过的兄弟给个提示。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: MySQLdb如何判断数据库连接有效?

leopay
connection.ping()

On 1/15/08, luo roger <[hidden email]> wrote:
用数据库连接池Dbutils,好像可以自动重连的。

在08-1-15,kun xu <[hidden email]> 写道:
做了一个程序,用到MySQLdb,这个程序需要一直保持对数据库的连接,没有在文档中看到如何判断当前数据库链接有效的函数?
有没有用过的兄弟给个提示。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: MySQLdb如何判断数据库连接有效?

leopay

>>> help(MySQLdb.connection.ping)
Help on method_descriptor:

ping(...)
    Checks whether or not the connection to the server is
    working. If it has gone down, an automatic reconnection is
    attempted.

    This function can be used by clients that remain idle for a
    long while, to check whether or not the server has closed the
    connection and reconnect if necessary.

    New in 1.2.2: Accepts an optional reconnect parameter. If True,
    then the client will attempt reconnection. Note that this setting
    is persistent. By default, this is on in MySQL<5.0.3, and off
    thereafter.

    Non-standard. You should assume that ping() performs an
    implicit rollback; use only when starting a new transaction.
    You have been warned.



On 1/15/08, leopay <[hidden email]> wrote:
connection.ping()


On 1/15/08, luo roger <[hidden email]> wrote:
用数据库连接池Dbutils,好像可以自动重连的。

在08-1-15,kun xu <[hidden email]> 写道:
做了一个程序,用到MySQLdb,这个程序需要一直保持对数据库的连接,没有在文档中看到如何判断当前数据库链接有效的函数?
有没有用过的兄弟给个提示。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank">http://python.cn/mailman/listinfo/python-chinese



_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: MySQLdb如何判断数据库连接有效?

kun xu-3
谢谢各位,之前都是用抛异常的方式处理数据库可能出现连接断开的问题,现在好了,再次感谢。


在08-1-15,leopay <[hidden email]> 写道:

>>> help(MySQLdb.connection.ping)
Help on method_descriptor:

ping(...)
    Checks whether or not the connection to the server is
    working. If it has gone down, an automatic reconnection is
    attempted.

    This function can be used by clients that remain idle for a
    long while, to check whether or not the server has closed the
    connection and reconnect if necessary.

    New in 1.2.2: Accepts an optional reconnect parameter. If True,
    then the client will attempt reconnection. Note that this setting
    is persistent. By default, this is on in MySQL<5.0.3, and off
    thereafter.

    Non-standard. You should assume that ping() performs an
    implicit rollback; use only when starting a new transaction.
    You have been warned.



On 1/15/08, leopay <[hidden email]> wrote:
connection.ping()


On 1/15/08, luo roger <[hidden email]> wrote:
用数据库连接池Dbutils,好像可以自动重连的。

在08-1-15,kun xu <[hidden email]> 写道:
做了一个程序,用到MySQLdb,这个程序需要一直保持对数据库的连接,没有在文档中看到如何判断当前数据库链接有效的函数?
有没有用过的兄弟给个提示。

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a href="http://python.cn/mailman/listinfo/python-chinese" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: <a href="http://python.cn/mailman/listinfo/python-chinese" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://python.cn/mailman/listinfo/python-chinese



_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a href="http://python.cn/mailman/listinfo/python-chinese" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese