Pythonpython连接mysql数据库安装 安装 pip3 install pymysql python3 import pymysql python2 import MySQLdb 操作sql 增 import pymysql conn = pymysql.connect( host='192.168.0.103', port=3306, user='root', password='123'作者王明昌发布时间2019-10-05最后更新2019-10-05文章目录安装操作sql安装 安装 pip3 install pymysql python3 import pymysql python2 import MySQLdb操作sql 增 复制import pymysql conn = pymysql.connect( host='192.168.0.103', port=3306, user='root', password='123', database='xing', charset='utf8' ) cursor = conn.cursor() # 获取一个光标 sql = 'insert into userinfo (user,pwd) values (%s,%s);' name = 'wuli' pwd = '123456789' cursor.execute(sql, [name, pwd]) conn.commit() last_id = cursor.lastrowid print("最后一条数据的ID是:", last_id) cursor.close() conn.close() 删 复制import pymysql # 建立连接 conn = pymysql.connect( host="192.168.0.103", port=3306, user="root", password="123", database="xing", charset="utf8" ) # 获取一个光标 cursor = conn.cursor() # 定义将要执行的SQL语句 sql = "delete from userinfo where user=%s;" name = "june" # 拼接并执行SQL语句 cursor.execute(sql, [name]) # 涉及写操作注意要提交 conn.commit() # 关闭连接 cursor.close() conn.close() 改 复制import pymysql # 建立连接 conn = pymysql.connect( host="192.168.0.103", port=3306, user="root", password="123", database="xing", charset="utf8" ) # 获取一个光标 cursor = conn.cursor() # 定义将要执行的SQL语句 sql = "update userinfo set pwd=%s where user=%s;" # 拼接并执行SQL语句 cursor.execute(sql, ["july", "july"]) # 涉及写操作注意要提交 conn.commit() # 关闭连接 cursor.close() conn.close() 查 复制import pymysql conn = pymysql.connect( host='192.168.0.103', port=3306, user='root', password='123', database='xing', charset='utf8' ) # 获取一个光标 cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 返回字典数据类型 # 定义将要执行的sql语句 sql = 'select user,pwd from userinfo;' # 拼接并执行sql语句 cursor.execute(sql) # 取到查询结果 ret1 = cursor.fetchone() # 取一条 ret2 = cursor.fetchmany(3) # 取三条 ret3 = cursor.fetchone() # 取一条 cursor.close() conn.close() print(ret1) print(ret2) print(ret3) # 可以获取指定数量的数据 cursor.fetchmany(3) # 光标按绝对位置移动1 cursor.scroll(1, mode="absolute") # 光标按照相对位置(当前位置)移动1 cursor.scroll(1, mode="relative")
2018-01-052017传智播客黑马Python就业+基础班视频教程好像python挺火的,最近学计算机的同学也建议我接触学习一下,某宝买的教程分享出来,大家各取所需。 基础班和软件:https://pan.baidu.com/s/1hr6zAbM 密码:[reply
2019-10-05python request模块sign token获取不到可测试手机端 百度翻译(案例) import requests header = { 'user-agent': 'Mozilla/5.0 (Linux; Android
2019-10-05python 案例itchat 查看手机微信中用户比例 import itchat import pandas as pd # Python抓取微信好友数量、性别、城市分布,以及将py文件打包成exe. #https:
2019-10-05python 通用爬虫(百度贴吧)import requests class TiebaSpider(): def __init__(self,tieba_name): self.tieba_name = tieba_name pri
2018-12-25Python | 从零学习pythonmac下载/安装环境 https://www.python.org/downloads/release/python-372/ 测试是否安装(命令行) python3 //mac自带python2 出
2020-07-29python 采集唯美girlimport requests; import re; import os; # 1.请求网页 header = { "user-agent":'Mozilla/5.0 (Macintosh; Int