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

相关推荐
kcuwu.26 分钟前
Python面向对象:封装、继承、多态
开发语言·python
YuanDaima204830 分钟前
LangChain基础配置与对话模型实战
人工智能·python·langchain·大模型·智能体·langgraph
河西石头32 分钟前
分享python项目与开源python项目中的效率法宝--requirements文件的使用
开发语言·python·requirements文件·批量安装python依赖·python虚拟环境配置
不懒不懒1 小时前
【卷积神经网络作业实现人脸的关键点定位功能】
开发语言·python
Bert.Cai1 小时前
Python集合简介
开发语言·python
tryCbest1 小时前
Java和Python开发项目部署简介
java·开发语言·python
ZTLJQ1 小时前
任务调度的艺术:Python分布式任务系统完全解析
开发语言·分布式·python
敏编程1 小时前
一天一个Python库:isodate - 处理 ISO 8601 日期时间格式
python
Bert.Cai1 小时前
Python字面量详解
开发语言·python
Flying pigs~~1 小时前
基于Deepseek大模型API完成文本分类预测功能
java·前端·人工智能·python·langchain·deepseek