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

相关推荐
忧郁的橙子.8 小时前
26期_01_Pyhton判断语句
python
快乐小胡!8 小时前
【自动化测试】Selenium选择/定位元素的基本方法
python·selenium·测试工具
高洁018 小时前
数字孪生与数字样机的技术基础:建模与仿真
python·算法·机器学习·transformer·知识图谱
喵手8 小时前
Python爬虫零基础入门【第二章:网页基础·第4节】新手最常栽的坑:编码、时区、空值、脏数据!
爬虫·python·python爬虫实战·python爬虫工程化实战·python爬虫零基础入门·python爬虫编码时区·爬虫编码时区
淡忘旧梦9 小时前
词错误率/WER算法讲解
人工智能·笔记·python·深度学习·算法
癫狂的兔子9 小时前
【Python】【爬虫】爬取虎扑网NBA排行数据
数据库·爬虫·python
Aurora-Borealis.9 小时前
Day40 早停策略和模型权重的保存
python
好大哥呀9 小时前
如何在手机上运行Python程序
开发语言·python·智能手机
_codemonster9 小时前
手语识别及翻译项目实战系列(一)环境准备
人工智能·python·计算机视觉
毕设源码-钟学长9 小时前
【开题答辩全过程】以 基于Python的新闻热点舆情分析系统为例,包含答辩的问题和答案
开发语言·python