您好,登錄后才能下訂單哦!
運(yùn)用Python腳本進(jìn)行MySQL對所有表收集統(tǒng)計(jì)信息,針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
[root@MySQL01 script]# vim analyze.py
#!/usr/bin/env python
# -*-encoding:utf8-*-
#
import MySQLdb
import time
step = 0
db = MySQLdb.connect(host = '192.168.56.101',port = 3306,user = 'neo', passwd = 'neo' , db = 'information_schema')
conn = db.cursor()
sql = '''select TABLE_SCHEMA, table_name from information_schema.tables where table_schema not in ('information_schema', 'performance_schema', 'mysql') '''
# print sql
conn.execute(sql)
if conn.rowcount > 0:
for item in conn.fetchall():
sql = '''analyze table %s.%s''' % (item[0], item[1])
print sql + ' operation executes successfully!'
conn.execute(sql)
time.sleep(0.5)
conn.close()
db.close()
# 執(zhí)行腳本
[root@MySQL01 script]# python2.6 analyze.py
analyze table test.area operation executes
analyze table test.class operation executes
關(guān)于運(yùn)用Python腳本進(jìn)行MySQL對所有表收集統(tǒng)計(jì)信息問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(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)容。