Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions mysql-py/mysql-conn.py
Original file line number Diff line number Diff line change
@@ -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.

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

password = 'redhat'
database = 'mysql'
#socket ='/tmp/mysql-master5520.sock'

# Simple routine to run a query on a database and print the results:
def Query( conn ) :
print "Printing user and hosts from the box\n"
cur = conn.cursor()
cur.execute( "SELECT user,host FROM user" )
# for row in cur :
row = cur.fetchone()
while row is not None:
print row[0], row[1]
row = cur.fetchone()
# print (row)

def index ( conn1 ) :
cur = conn1.cursor()
Expand All @@ -25,7 +20,6 @@ def index ( conn1 ) :
for row in cur :
print (row)


def data_big ( conn3 ) :
cur = conn3.cursor()
print "\n\nFind biggest db"
Expand All @@ -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.

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 ?

Query( connect )
Expand Down