午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Python 如何實現數據庫表結構同步

瀏覽:15日期:2022-07-09 14:31:44

近日,某個QQ 群里的一個朋友提出一個問題,如何將一個DB 的表結構同步給另一個DB。針對這個問題,我進行了思考與實踐,具體的實現代碼如下所示:

# coding:utf-8import pymysqldbDict = {'test1':'l-beta.test1'}dbUser = 'test'dbPassword = '123456'class DBUtils(): def __init__(self): self.conn = pymysql.connect(dbDict[’test1’], dbUser, dbPassword) self.cursor = self.conn.cursor() def dbSelect(self, sql): print('------------------------------------') print(sql) resultList = [] self.cursor.execute(sql) result = self.cursor.fetchall() columns = self.cursor.description for val in result: tempDict = {} for cloNum in range(len(columns)):tempDict[str(columns[cloNum][0])] = val[cloNum] resultList.append(tempDict) print('---------------------打印查詢結果----------------------') print(resultList) self.dbClose() return resultList def dbExcute(self, sql): print(sql) self.cursor.execute(sql) self.dbClose() def dbClose(self): self.conn.commit() self.cursor.close() self.conn.close()if __name__ == '__main__': test = DBUtils() result = test.dbSelect('select table_name from information_schema.tables where table_schema=’testdb1’') for dict1 in result: test = DBUtils() create_table_sql = 'create table testdb.%s as select * from testdb1.%s' % (dict1[’table_name’],dict1[’table_name’]) print(create_table_sql) test.dbExcute(create_table_sql)

示例代碼操作簡單,通俗易懂,所以沒有過多的注釋,如有疑問的小伙伴們,可在文章下方評論。

以上就是Python 如何實現數據庫表結構同步的詳細內容,更多關于Python 數據庫表結構同步的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 午夜精品区 | 国产精品91视频 | 免费黄色网址大全 | 久久成人精品视频 | 四虎影院在线免费播放 | 国产精品视频区 | 操在线视频 | 天堂av官网 | 成人在线网站 | 97超碰97| 天天干天天操天天操 | 日本黄色大片免费 | 国产成人三级在线观看 | 视频1区2区 | 精品一区二区三区免费看 | 亚洲国产欧美另类 | 日韩一级片中文字幕 | 成人在线视频网址 | 99国产一区| 欧美片一区二区三区 | 四虎精品久久 | 国产最新在线视频 | av在线影院 | 日韩99| 国产成人精品一区二区三区四区 | 国久久久 | 国内精品视频一区 | 日韩欧美一区二区视频 | 成年视频在线播放 | 毛片在线免费 | 丁香午夜 | 日本免费黄色大片 | 亚洲精品成人在线视频 | 久久人人澡 | 欧美精品亚洲精品 | 久久久久久色 | 欧美三级欧美一级 | 欧美日韩专区 | 欧美亚洲日本国产 | 欧美精品欧美精品系列 | 国产成人一区二区三区 |