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

相关推荐
胡耀超18 分钟前
从一次批量爬取到生产同步:问题变了,建设边界也要跟着变
爬虫·python·系统架构·数据治理·数据同步·接口设计·爬虫工程
旅僧34 分钟前
王树森老师强化学习--同声传译版3
python·深度学习
梦想不只是梦与想37 分钟前
python中精度处理:decimal
python·float·精度丢失·decimal·浮点运算
大模型码小白41 分钟前
向量化引擎与 AI 排障:当 SIMD 遇到异常检测,存储诊断的范式转移
java·大数据·数据库·人工智能·python
雪的季节1 小时前
【无标题】
linux·服务器·python
sa100271 小时前
搭建京东评论监控系统,自动捕捉新增评价,快速挖掘用户真实痛点
python
weixin_461769402 小时前
anaconda安装pytorch安装python
人工智能·pytorch·python
梅雅达编程笔记2 小时前
编程启蒙|Scratch 转 Python 系列第10天:问答闯关游戏实战(AI题库管理+随机出题实战)
人工智能·python·游戏·青少年编程
AOwhisky2 小时前
Python 学习笔记(第十一期)——运维自动化(上·后篇):进程级监控与子进程管理——psutil进阶
运维·开发语言·python·学习·云原生·运维开发
人工干智能2 小时前
Python 的链式调用:一连串的“点”调用
开发语言·python