当前位置: 首页 > news >正文

通过python 操作mysql 脚本


#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymysql
import pymysql.cursors
import datetime
import time
def delData(min_id,max_id):# 连接MySQL数据库connection = pymysql.connect(host='192.168.3.XX', port=33XX, user='apps_new_w', password='BsMtABQi', db='userdata',charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)# 通过cursor创建游标cursor = connection.cursor()sql = "delete from `user_table` where id >= %s and id <= %s limit 10000"print(sql)# 执行数据查询cursor.execute(sql,[min_id,max_id])#查询数据库单条数据connection.commit()print(cursor.rowcount,"记录已删除")# 关闭数据连接connection.close()return
minNum =1
maxNum =1612818680579782
limit = 10000000
cha = maxNum - minNum
rangeNum = int(cha/limit)
start = minNum
for i in range(rangeNum):end = start + limitprint(start,end)delData(start,end)start = endtime.sleep(0.1)

1. 一个问题是:SyntaxError: Non-ASCII character '\xe8' in file deleteMysql.py on line 9

2. pip install pymysql 


http://www.mrgr.cn/news/16414.html

相关文章:

  • “品牌VS套路:华为、格行、中兴随身WiFi谁才是真良心?“
  • VMware中CentOS虚拟机配置网络(Net模式)
  • git commit添加emoji表情
  • 从零开始自学Python-之-常用库篇(十四)python的异步编程库asyncio
  • Tampermonkey 安装
  • Call openai-node in the backend or call https in the frontend?
  • 【flask】python框架flask的hello world
  • [ABC001A] 積雪深差
  • 自闭症儿童托管学校
  • 全面解读LSC局域网屏幕监控软件:功能、优势与应用场景一网打尽!
  • vaspup2.0介绍
  • spring security 会话管理
  • 如何打开终端?
  • 06:网表更新到PCB
  • macOS搭建Python3.11+Django4.2.15的平台框架使用Poetry管理
  • 最新版 Java 网络编程|万字笔记
  • Linux学习(17)-I/O复用(1)select、poll
  • BUUCTF PWN wp--jarvisoj_level0
  • 4.负载均衡
  • 可以根据手机的折叠状态改变播放音效:nova Flip 的妙趣音效