-
Notifications
You must be signed in to change notification settings - Fork 6
/
execute_mysql_query
executable file
·44 lines (38 loc) · 2.08 KB
/
execute_mysql_query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python
# pluo, Apr 1, 2013
# PATH=$PATH:/home/dataproc/bi/lib/python # add python lib to path
# execute_mysql_query --mysql_query='desc opportunity'
# execute_mysql_query --mysql_query='select count(*) from opportunity'
# execute_mysql_query --mysql_query='drop table if exists tmp_fpv'
import legoo
import sys
from optparse import OptionParser
def main():
parser = OptionParser()
parser.add_option("--mysql_host", dest="mysql_host",
help="mysql host. default: [bidbs]", default='bidbs')
parser.add_option("--mysql_db", dest="mysql_db",
help="mysql db. default: [staging]", default='staging')
parser.add_option("--mysql_user", dest="mysql_user",
help="mysql user, if not specified, get user from [mysql_ini]")
parser.add_option("--mysql_password", dest="mysql_password",
help="mysql password, if not specified, get password from [mysql_ini]")
parser.add_option("--mysql_query", dest="mysql_query", help="mysql query")
parser.add_option("--row_count", dest="row_count", help="OPTIONAL: row_count default: [N]", default='N')
parser.add_option("-q", "--quiet", "--silent", dest="quiet",
help="OPTIONAL: suppress messages to stdout. default: [N]", default='N')
parser.add_option("-d", "--debug", dest="debug", help="OPTIONAL: debug flag [Y|N], default: [N]", default='N')
(options, args) = parser.parse_args()
rs = legoo.execute_mysql_query( mysql_host = options.mysql_host, \
mysql_db = options.mysql_db, \
mysql_user = options.mysql_user, \
mysql_password = options.mysql_password, \
mysql_query = options.mysql_query, \
row_count = options.row_count, \
quiet = options.quiet, \
debug = options.debug
)
for i in rs:
print i
if __name__ == '__main__':
main()