溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么樣的Python腳本進(jìn)行MySQL對所有表收集統(tǒng)計(jì)信息

發(fā)布時(shí)間:2021-10-11 18:25:56 來源:億速云 閱讀:107 作者:柒染 欄目:MySQL數(shù)據(jù)庫

運(yùn)用Python腳本進(jìn)行MySQL對所有表收集統(tǒng)計(jì)信息,針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。

  1. [root@MySQL01 script]# vim analyze.py

  2. #!/usr/bin/env python

  3. # -*-encoding:utf8-*-

  4. #


  5. import MySQLdb

  6. import time

  7. step = 0

  8. db = MySQLdb.connect(host = '192.168.56.101',port = 3306,user = 'neo', passwd = 'neo' , db = 'information_schema')

  9. conn = db.cursor()


  10. sql = '''select TABLE_SCHEMA, table_name from information_schema.tables where table_schema not in ('information_schema', 'performance_schema', 'mysql') '''

  11. # print sql

  12. conn.execute(sql)

  13. if conn.rowcount > 0:

  14.         for item in conn.fetchall():

  15.                 sql = '''analyze table %s.%s''' % (item[0], item[1])

  16.                 print sql + ' operation executes successfully!'

  17.                 conn.execute(sql)


  18. time.sleep(0.5)


  19. conn.close()

  20. db.close()


  21. # 執(zhí)行腳本

  22. [root@MySQL01 script]# python2.6 analyze.py

  23. analyze table test.area operation executes

  24. analyze table test.class operation executes

關(guān)于運(yùn)用Python腳本進(jìn)行MySQL對所有表收集統(tǒng)計(jì)信息問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI