python之数据库表迁移
时间:2021-07-01 10:21:17
帮助过:3人阅读
#!/usr/local/bin/python3.5
2 #coding:utf-8
3 import pymysql
4 import datetime
5 Host =
‘xxxxxxxx‘
6 User =
‘xxxxxx‘
7 Pass =
‘xxxxxx‘
8 Db =
‘xxxxxxx‘
9
10 db =
pymysql.connect(Host, User, Pass, Db)
11 cursor =
db.cursor()
12 sql =
‘‘‘
13 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
14 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
15
16 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
17
18
19 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx21 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
22
23 ‘‘‘
24 try:
25 starttime =
datetime.datetime.now()
26 cursor.execute(sql)
27 db.commit()
28 endtime =
datetime.datetime.now()
29 print(u
"执行成功......\n共运行:", (endtime - starttime).seconds,
‘s‘)
30 except Exception as e:
31 print(e)
32 db.rollback()
33
34 db.close()
END !
python之数据库表迁移
标签: