通过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 分钟前
【open3d】示例:自动计算点人脸点云模型面部朝向算法
人工智能·python·算法
lalala_lulu14 分钟前
Lambda表达式是什么
开发语言·python
r***869819 分钟前
Python中的简单爬虫
爬虫·python·信息可视化
atregret27 分钟前
OSError: [WinError 1114] 动态链接库(DLL)初始化例程失败。Error loading ... c10.dll
人工智能·python
zhongtianhulian1 小时前
江苏设备管理平台哪家好
大数据·运维·python
love530love1 小时前
【ComfyUI/SD环境管理指南(二)】:如何避免插件安装导致的环境崩溃与“外科手术式”修复
人工智能·windows·python·stable diffusion·github·aigc·comfyui
编程修仙1 小时前
第五章 Spring XML配置原理
xml·python·spring
江上鹤.1481 小时前
Day25评价问题
python
万行1 小时前
英语作文模板
python
韩立学长1 小时前
【开题答辩实录分享】以《计算机类专业招聘信息爬取与查询系统设计与实现》为例进行答辩实录分享
python·scrapy·django