-
Notifications
You must be signed in to change notification settings - Fork 0
Commiting mysql-connection code for review #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
mysql-py/mysql-conn.py
Outdated
@@ -1,22 +1,17 @@ | |||
#!/usr/bin/python | |||
|
|||
hostname = '127.0.0.1' |
There was a problem hiding this comment.
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.
mysql-py/mysql-conn.py
Outdated
@@ -1,22 +1,17 @@ | |||
#!/usr/bin/python | |||
|
|||
hostname = '127.0.0.1' | |||
username = 'root' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as previous comment
mysql-py/mysql-conn.py
Outdated
@@ -40,8 +34,7 @@ def data_dist ( conn4 ) : | |||
for row in cur : | |||
print (row) | |||
|
|||
print "======Using pymysql========" | |||
print " " | |||
|
|||
import pymysql as my |
There was a problem hiding this comment.
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.
mysql-py/mysql-conn.py
Outdated
@@ -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 ) |
There was a problem hiding this comment.
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;" |
There was a problem hiding this comment.
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 ?
mysql-py/mysql-conn.py
Outdated
|
||
|
||
def parse_options(): | ||
parser = argparse.ArgumentParser() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
Kindly review the code for sample script for connection