forked from jly8866/archer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Django==1.8.17 | ||
python==3.4.1 | ||
MySQLdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# coding = utf-8 | ||
|
||
import MySQLdb | ||
|
||
class Dao(object): | ||
#连进指定的mysql实例里,读取所有databases并返回 | ||
def getAlldbByCluster(self, masterHost, masterPort, masterUser, masterPassword): | ||
listDb = [] | ||
try: | ||
conn=MySQLdb.connect(host=masterHost, port=masterPort, user=masterUser, passwd=masterPassword) | ||
cursor = conn.cursor() | ||
sql = "show databases" | ||
n = cursor.execute(sql) | ||
listDb = [row[0] for row in cursor.fetchall() | ||
if row[0] not in ('information_schema', 'performance_schema', 'mysql', 'test')] | ||
except MySQLdb.Warning as w: | ||
print(str(w)) | ||
except MySQLdb.Error as e: | ||
print(str(e)) | ||
finally: | ||
cursor.close() | ||
conn.commit() | ||
conn.close() | ||
return listDb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#-*-coding: utf-8-*- | ||
|
||
import MySQLdb | ||
from django.conf import settings | ||
|
||
class InceptionDao(object): | ||
def __init__(self): | ||
try: | ||
self.inception_host = getattr(settings, 'INCEPTION_HOST') | ||
self.inception_port = getattr(settings, 'INCEPTION_PORT') | ||
except AttributeError as a: | ||
print("Error:%s" % a) | ||
quit(1) | ||
|
||
|
||
def sqlautoReview(self, sql_content, cluster_name): | ||
sql='/*--user=username;--password=password;--host=127.0.0.1;--execute=1;--port=3306;*/\ | ||
inception_magic_start;\ | ||
use mysql;\ | ||
CREATE TABLE adaptive_office(id int);\ | ||
inception_magic_commit;' | ||
try: | ||
conn=MySQLdb.connect(host='127.0.0.1',user='',passwd='',db='',port=9998) | ||
cur=conn.cursor() | ||
ret=cur.execute(sql) | ||
result=cur.fetchall() | ||
num_fields = len(cur.description) | ||
field_names = [i[0] for i in cur.description] | ||
print field_names | ||
for row in result: | ||
print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|", | ||
row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10] | ||
cur.close() | ||
conn.close() | ||
except MySQLdb.Error,e: | ||
print "Mysql Error %d: %s" % (e.args[0], e.args[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters