#!/usr/bin/python3.3
#The objetive of this script is to find all tables in a MYSQL DB and opmitize all of them
import dbconnect
import time
from datetime import datetime
## // VARIABLE DECLARATION ##//
startTime = datetime.now()
conn = dbconnect.dbconnect()
conn.autocommit(True)
cur = conn.cursor()
print ("Starting time: ", startTime)
SQLQUERY=("SHOW TABLES") #Find every table in the DB
cur.execute(SQLQUERY)
tables = cur.fetchall()
if len(tables)>0: #Prevent there are not tables in the list
for table in tables: #For every table in the DB
try:
SQLQUERY="OPTIMIZE TABLE "+ table[0] #Construct the SQL QUERY
print (" Optimizing", table[0])
cur.execute(SQLQUERY)
except:
pass
print ("Script execution time:",datetime.now()-startTime)
print ("Ending time: ", datetime.now())
print ("******** ****** ")
No hay comentarios:
Publicar un comentario
¿Algo adicional que quieras mencionar? ¿Algun consejo?, ¿truco? Gracias!