通过python 操作mysql 脚本

python 复制代码
#!/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 + limit
    print(start,end)
    delData(start,end)
    start = end
    time.sleep(0.1)
  1. 一个问题是:SyntaxError: Non-ASCII character '\xe8' in file deleteMysql.py on line 9

  2. pip install pymysql

相关推荐
生信大表哥1 小时前
单细胞测序分析(五)降维聚类&数据整合
linux·python·聚类·数信院生信服务器
seeyoutlb2 小时前
微服务全局日志处理
java·python·微服务
ada7_2 小时前
LeetCode(python)——148.排序链表
python·算法·leetcode·链表
岁月宁静3 小时前
LangChain + LangGraph 实战:构建生产级多模态 WorkflowAgent 的完整指南
人工智能·python·agent
第二只羽毛4 小时前
主题爬虫采集主题新闻信息
大数据·爬虫·python·网络爬虫
plmm烟酒僧4 小时前
TensorRT 推理 YOLO Demo 分享 (Python)
开发语言·python·yolo·tensorrt·runtime·推理
天才测试猿4 小时前
Postman中变量的使用详解
自动化测试·软件测试·python·测试工具·职场和发展·接口测试·postman
帕巴啦4 小时前
Arcgis计算面要素的面积、周长、宽度、长度及最大直径
python·arcgis
AI小云5 小时前
【数据操作与可视化】Matplotlib绘图-生成其他图表类型
开发语言·python·matplotlib
MediaTea5 小时前
Python 第三方库:plotnine(类 ggplot 的 Python 数据可视化库)
开发语言·python·信息可视化