通过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

相关推荐
小陈工14 小时前
Python Web开发入门(十二):使用Flask-RESTful构建API——让后端开发更优雅
开发语言·前端·python·安全·oracle·flask·restful
无心水14 小时前
20、Spring陷阱:Feign AOP切面为何失效?配置优先级如何“劫持”你的设置?
java·开发语言·后端·python·spring·java.time·java时间处理
夜雨飘零115 小时前
零门槛!用 AI 生成 HTML 并一键部署到云端桌面
人工智能·python·html
qZ6bgMe4315 小时前
使用Mixin类简单重构配置模块
网络·python·重构
巧妹儿15 小时前
AI Agent 实战:MySQL 监控指标查询 Skill|华为云 + 腾讯云双兼容可直接复用
python·mysql·ai·大模型·华为云·腾讯云
ZC跨境爬虫16 小时前
免费验证码识别:用ddddocr实现Playwright自动化登录
爬虫·python·自动化
数据知道16 小时前
claw-code 源码详细分析:子系统目录地图——几十个顶层包如何用五条轴(会话 / 工具 / 扩展 / 入口 / 桥接)读懂?
服务器·python·ai·claude code
cxr82816 小时前
GPU 加速声场求解器 - 深度扩展
人工智能·python
zaim116 小时前
计算机的错误计算(二百二十六)
java·python·c#·c·错数·mpmath
EmmaXLZHONG16 小时前
Django By Example - 学习笔记
笔记·python·学习·django