Skip to content

Conversation

code-sidd
Copy link
Owner

Kindly review the code for sample script for connection

@@ -1,22 +1,17 @@
#!/usr/bin/python

hostname = '127.0.0.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this parameters dynamic ? Use a getopts like tool to parse arguments.

@@ -1,22 +1,17 @@
#!/usr/bin/python

hostname = '127.0.0.1'
username = 'root'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment

@@ -40,8 +34,7 @@ def data_dist ( conn4 ) :
for row in cur :
print (row)

print "======Using pymysql========"
print " "

import pymysql as my

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import should always be on the top of the file. Even though the script has a main function, imports should always go to the top.

@@ -40,8 +34,7 @@ def data_dist ( conn4 ) :
for row in cur :
print (row)

print "======Using pymysql========"
print " "

import pymysql as my
connect = my.connect( host=hostname, user=username, passwd=password, db=database )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be made to use a .my.cnf file ?

def data_big():
cursor = get_mysql_conn(options.host, options.port_no).cursor(mysql.cursors.DictCursor)
print "\nFind biggest db\n"
sql= "SELECT count(*) tables,table_schema,concat(round(sum(table_rows)/1000000,2),'M') rows, concat(round(sum(data_length)/(1024*1024*1024),2),'G') data, concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx, concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size, round(sum(index_length)/sum(data_length),2) idxfrac FROM information_schema.TABLES GROUP BY table_schema ORDER BY sum(data_length+index_length) DESC LIMIT 10;"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format the query on multiple lines ?



def parse_options():
parser = argparse.ArgumentParser()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow options for script to execute different types of queries. Something like mysql_conn.py -H -u -p -P --index.

from warnings import filterwarnings

def parse_options():
parser = argparse.ArgumentParser()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a argument for calling different types of query. And then use them in the main body to call the functions appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants