data = [("Atlanta","Georgia",1.25,6),("Tallahassee","Florida",2.6,3),("Sacramento","California",1.7,5)]
stmt = "INSERT INTO test VALUES(?,?,?,?)"
con.executemany(stmt,data)
con.commit()
查询
cursor = con.execute("select * from test")
rows = cursor.fetchall()
#coding=utf-8import pymysql
conn = pymysql.connect(host='localhost',port=3306,user="root",passwd="123",db="day39")
cur = conn.cursor()
#查询
cur.execute("select * from e1")
res = cur.fetchall()
res
#创建数据表
cur.execute("create table stud(id int,name varchar(20),class varchar(30),age varchar(10))")
#插入一条数据
cur.execute("insert into stud values(1,'Tom','3year2class','9')")
#修改数据
cur.execute("update stud set age='10' where name='Tom'")
#删除数据:
cur.execute("delete from stud where age='9'")
conn.commit()
cur.close()
conn.close()
2.3Memcache
#coding:utf8import memcache
classMemcachedClient():
''' python memcached 客户端操作示例 '''def__init__(self, hostList):
self.__mc = memcache.Client(hostList);
defset(self, key, value):
result = self.__mc.set("name", "NieYong")
return result
defget(self, key):
name = self.__mc.get("name")
return name
defdelete(self, key):
result = self.__mc.delete("name")
return result
if __name__ == '__main__':
mc = MemcachedClient(["127.0.0.1:11511", "127.0.0.1:11512"])
key = "name"
result = mc.set(key, "NieYong")
print"set的结果:", result
name = mc.get(key)
print"get的结果:", name
result = mc.delete(key)
print"delete的结果:", result
2.4MongoDB
#encoding:utf=8 import pymongo
connection=pymongo.Connection('10.32.38.50',27017)
#选择myblog库
db=connection.myblog
# 使用users集合
collection=db.users
# 添加单条数据到集合中
user = {"name":"cui","age":"10"}
collection.insert(user)
#同时添加多条数据到集合中
users=[{"name":"cui","age":"9"},{"name":"cui","age":"11"}]
collection.insert(users)
#查询单条记录 print collection.find_one()
#查询所有记录 for data in collection.find():
print data
#查询此集合中数据条数 print collection.count()
#简单参数查询 for data in collection.find({"name":"1"}):
print data
#使用find_one获取一条记录 print collection.find_one({"name":"1"})
#高级查询 print"__________________________________________"print'''''collection.find({"age":{"$gt":"10"}})'''print"__________________________________________"for data in collection.find({"age":{"$gt":"10"}}).sort("age"):
print data
# 查看db下的所有集合 print db.collection_names()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库