运用Python脚本进行MySQL对所有表收集统计信息,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

[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()


# 执行脚本

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

analyze table test.area operation executes

analyze table test.class operation executes

关于运用Python脚本进行MySQL对所有表收集统计信息问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。