Test SQL statement Execution time

Source: Internet
Author: User

#-*-coding:utf-8-*-

Import Sys
Import OS
Import time
Import Traceback
Import MySQLdb as Sqldb
From log import TraceLog


Query_list = [
"SELECT COUNT (*) from T_fieldinfo,t_famtabledescinfo,t_dataeledesc;",
]

Def getconn ():
Host = ' 10.1.81.164 '
user = ' Db_user '
passwd = ' db_passwd '
dbname = ' db_name '
Return Sqldb.connect (Host,user,passwd,dbname)

def query_time (cursor,query):
Cursor.execute ("Flush hosts;")
Time.sleep (10)

BeginTime = Time.time ()
Cursor.execute (query)
Endtime = Time.time ()
Spantime = Endtime-begintime
Note = "sql:%s spantime:%s"% (Query,str (spantime))
Return note

Def openmysqport ():
Strcmd=r ' plink [email protected]%S-PW%s "iptables-d input-i bond1-p tcp--dport 3306-j DROP" '% (' 10.1.81. 164 ', ' root_passwd ')
Os.system (Strcmd)

def main ():
Tracelog.setlogfilename (r "./query_time_st.txt")
Tracelog.log ("======sql test begin==========")

Try
conn = Getconn ()
cursor = Conn.cursor ()
For query in Query_list:
Qnote = Query_time (cursor,query)
Tracelog.log (Qnote)
Except
expmsg = ". Join (Traceback.format_exception (*sys.exc_info ()))
Tracelog.log (EXPMSG)
Finally
Cursor.close ()
Conn.close ()

Tracelog.log ("======sql test end==========")

if __name__ = = ' __main__ ':
Main ()

Test SQL statement Execution time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.