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

相关推荐
七夜zippoe5 分钟前
事件驱动架构:构建高并发松耦合系统的Python实战
开发语言·python·架构·eda·事件驱动
Kratzdisteln19 分钟前
【MVCD】PPT提纲汇总
经验分享·python
一个无名的炼丹师1 小时前
GraphRAG深度解析:从原理到实战,重塑RAG检索增强生成的未来
人工智能·python·rag
用户8356290780511 小时前
用Python轻松管理Word页脚:批量处理与多节文档技巧
后端·python
进击的松鼠2 小时前
LangChain 实战 | 快速搭建 Python 开发环境
python·langchain·llm
小北方城市网2 小时前
第1课:架构设计核心认知|从0建立架构思维(架构系列入门课)
大数据·网络·数据结构·python·架构·数据库架构
我的offer在哪里2 小时前
Hugging Face:让大模型触手可及的魔法工厂
人工智能·python·语言模型·开源·ai编程
汤姆yu2 小时前
基于python大数据的协同过滤音乐推荐系统
大数据·开发语言·python
爱学习的小道长2 小时前
Python Emoji库的使用教程
开发语言·python
Data_agent2 小时前
Cssbuy 模式淘宝 / 1688 代购系统南美市场搭建指南
大数据·python