#/usr/bin/python
#_*_ coding:utf-8 _*_
import pymysql.cursors
sql='/*--user=root;--password=123456;--host=192.168.10.81;--execute=1;--port=3306;*/\
inception_magic_start;\
use hequan;\
CREATE TABLE adaptive_office(id int);\
inception_magic_commit;'
try:
conn=pymysql.connect(host='127.0.0.1',user='',passwd='',db='',port=6669)
cursor=conn.cursor()
cursor.execute(sql)
results = cursor.fetchall()
column_name_max_size=max(len(i[0]) for i in cursor.description)
row_num=0
for result in results:
row_num=row_num+1
print('*'.ljust(27,'*'),row_num,'.row', '*'.ljust(27,'*'))
row = map(lambda x, y: (x,y), (i[0] for i in cursor.description), result)
for each_column in row:
if each_column[0] != 'errormessage':
print(each_column[0].rjust(column_name_max_size),":",each_column[1])
else:
print(each_column[0].rjust(column_name_max_size),':',each_column[1].replace('\n','\n'.ljust(column_name_max_size+4)))
cursor.close()
conn.close()
except pymysql.Error as e:
print("Mysql Error %d: %s" % (e.args[0], e.args[1]))
*************************** 1 .row ***************************
ID : 1
stage : CHECKED
errlevel : 0
stagestatus : Audit completed
errormessage : None
SQL : use hequan
Affected_rows : 0
sequence : '0_0_0'
backup_dbname : None
execute_time : 0
sqlsha1 :
*************************** 2 .row ***************************
ID : 2
stage : CHECKED
errlevel : 2
stagestatus : Audit completed
errormessage : Table 'adaptive_office' already exists.
Set engine to innodb for table 'adaptive_office'.
Set charset to one of 'utf8mb4' for table 'adaptive_office'.
Set comments for table 'adaptive_office'.
Column 'id' in table 'adaptive_office' have no comments.
Column 'id' in table 'adaptive_office' is not allowed to been nullable.
Set Default value for column 'id' in table 'adaptive_office'
Set a primary key for table 'adaptive_office'.
SQL : CREATE TABLE adaptive_office(id int)
Affected_rows : 0
sequence : '0_0_1'
backup_dbname : 192_168_10_81_3306_hequan
execute_time : 0
sqlsha1 :