1.安装python
地址:python安装
2.安装PyMySQL
在dos下进入python的Scripts目录:
执行:pip install PyMySQL
3.编写py文件
我的内容如下:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pymysql
db=pymysql.connect("rm-uf6il7eb0xs91srzkso.mysql.rds.aliyuncs.com","appuser","PHI!e2eNet4u","smart_hardware")
cursor=db.cursor()
# 修改此处手机号码
phonenumber = "13611923025"
# SQL插入语句
sql1='SELECT * FROM dbname.account WHERE phonenumber = "'+phonenumber+'"'
sql2='DELETE FROM dbname.account_data WHERE uid = (SELECT uid FROM dbname.account WHERE phonenumber = "'+phonenumber+'")'
try:
# 执行sql语句
cursor.execute(sql1)
cursor.execute(sql2)
# 获取全部查询结果,取一条为 fetchone()
#result = cursor.fetchall()
#print(result)
# 提交到数据库
db.commit()
except:
# 发生错误时回滚
db.rollback()
# 关闭数据库连接
db.close()
4.执行
dos进入py文件所在的盘符,执行python xx.py