#创建临时数据表 import pymysql pymysql.install_as_MySQLdb() """ www.jjddlc.com""" """作者:Pgabc""" def stock_tmp_md(dbnm_wm,itemnv_nv): try: # 建立数据库连接 db = pymysql.connect(host='127.0.0.1', user='root', passwd='xxxxxx', db=dbnm_wm, charset='utf8') cursor = db.cursor() query = "create table stock_tmp like {}".format(itemnv_nv) cursor.execute(query) db.commit() print('stock_tmp表已建立') except Exception as aa: # print(aa) print('已存在TMP表,删除再建') query = "drop table stock_tmp " cursor.execute(query) db.commit() query = "create table stock_tmp like {}".format(itemnv_nv) cursor.execute(query) db.commit() print('stock_tmp表已重新建立') if __name__=='__main__': dbnm_wm = 'stock' #mysql数据库名 dbnm = 'stock_all' #mysql数据表名 stock_tmp_md(dbnm_wm,dbnm)
python 在数据分析中根据mysql数据库生成临时数据表
最新推荐文章于 2024-07-07 16:33:06 发布