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

相关推荐
电院工程师16 小时前
SIMON64/128算法Verilog流水线实现(附Python实现)
python·嵌入式硬件·算法·密码学
Python图像识别17 小时前
75_基于深度学习的咖啡叶片病害检测系统(yolo11、yolov8、yolov5+UI界面+Python项目源码+模型+标注好的数据集)
python·深度学习·yolo
闲人编程17 小时前
Python游戏开发入门:Pygame实战
开发语言·python·游戏·pygame·毕设·codecapsule
雍凉明月夜18 小时前
人工智能学习中深度学习之python基础之 类
python·学习
Geo_V18 小时前
OpenAI 大模型 API 使用示例
python·chatgpt·openai·大模型应用·llm 开发
Hello_WOAIAI18 小时前
2.4 python装饰器在 Web 框架和测试中的实战应用
开发语言·前端·python
百锦再19 小时前
第1章 Rust语言概述
java·开发语言·人工智能·python·rust·go·1024程序员节
tokepson19 小时前
chatgpt-to-md优化并重新复习
python·ai·技术·pypi·记录
Victory_orsh19 小时前
“自然搞懂”深度学习(基于Pytorch架构)——010203
人工智能·pytorch·python·深度学习·神经网络·算法·机器学习
java1234_小锋19 小时前
PyTorch2 Python深度学习 - 模型保存与加载
开发语言·python·深度学习·pytorch2