用明道云链接企业自有的数据库,读取数据再写入明道云。
pymysql
docker exec -t $(docker ps | grep community | awk '{print $1}') bash -c 'pip3 install --target=/usr/local/lib/python3.6/site-packages/ pymysql'
pymssql
docker exec -t $(docker ps | grep community | awk '{print $1}') bash -c 'pip3 install --target=/usr/local/lib/python3.6/site-packages/ pymssql'
/data/mingdao/script/volume/command/package/python-3.6/site-packages/
import pymysql import json output = {} output['result'] = '' # 打开数据库连接 try: db = pymysql.connect(host=input['host'], user=input['username'], password=input['passwd'], port=int(input['port'])) # 使用 cursor() 方法创建一个游标对象 cursor db.select_db(input['db']) cursor = db.cursor() # 使用 execute() 方法执行 SQL 查询 output['sql'] = input['sqltext'] cursor.execute(input['sqltext']) cols=cursor.description # 使用 fetchone() 方法获取单条数据. datas = cursor.fetchall() allop=[] for data in datas: i = 0 op= {} for col in cols: op[cols[cols.index(col)][i]] =str(data[cols.index(col)]) i=i+1 allop.append(op) output['data'] = json.dumps(allop, ensure_ascii=False) #print(output) # 关闭数据库连接 db.close() output['code'] = 0 output['msg'] = '连接成功' except Exception as e: output['code'] = 1 output['msg'] = '连接失败:{}'.format(e)
select table_name tableName ,ifnull(TABLE_COMMENT,'') as tabledesc,create_time createTime from information_schema.tables where table_schema ='数据库库名' order by create_time desc
select column_name as '列名',data_type as '字段类型',column_comment as '字段注释' ,column_key as '是否主键',is_nullable as '是否允许为空',column_default as '默认值' from information_schema.columns where table_schema='数据库库名' and table_name='表名'