如何使用sqlalchemy获得奴隶滞后?

时间:2012-09-11 16:02:58

标签: mysql sqlalchemy

有没有办法使用sql炼金术来获得当前的奴隶滞后? session.execute('show slave status')似乎不返回任何行:

In [0]: list(session.execute('show slave status'))

ResourceClosedError: This result object does not return rows. It has been closed automatically.

1 个答案:

答案 0 :(得分:2)

from sqlalchemy import create_engine

engine = create_engine('mysql+pymysql://username:password@your.hostname.com/')
connection = engine.connect()
result = connection.execute("SHOW SLAVE STATUS") 
for row in result:
   for k in row.keys():
     print k, ' >>> ', row[k]