Python 官方文档:入门教程 => 点击学习
需求: 要在服务器上指执行sql 为了不影响线上用户正常使用,且执行10000行暂停10秒。然后用python 写了这样一个文件文件存放位置: /root/sql/ 文件名:2 3 4 5 6 .....这样做是为了省事 用 range
需求: 要在服务器上指执行sql 为了不影响线上用户正常使用,且执行10000行暂停10秒。
然后用python 写了这样一个文件
文件存放位置: /root/sql/
文件名:2 3 4 5 6 .....
这样做是为了省事 用 range(2,24)
其实可以写成读取目录文件:os.listdir("/root/sql/")
######## author shenym ###########
########2014-05-05 ###########
import os
import time
import math
##读取文件
for i in range(2,24):
##拼接文件完整路径
filename="/root/sql/"+str(i)
file= open(filename,'r')
##计数器(控制暂停)
count=0
for line in file:
count +=1
if line:
lines=line[:line.find(';')]
cmd="Mysql -u root -pxxxx dbname -e "+'"'+lines+'"'
print cmd
os.system(cmd)
print count
if count == 10000:
time.sleep(10)
count=0
file.close()
--结束END--
本文标题: python 批量执行sql文件
本文链接: https://www.lsjlt.com/news/189205.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0