标签:mongod pass values 插入 roo ODB har into 连接数据库
mogodb:
client = pymongo.MongoClient(‘localhost‘, 27017) # 连接数据库
mydb = client[‘mydb‘] # 新建mysb数据库
test = mydb[‘test‘] # 新建test数据集合/表
# mongoDB数据库只有插入数据才会建库建表
test.insert_one({‘name‘: ‘Jan‘, ‘sex‘: ‘男‘, ‘grade‘: ‘98‘}) # 插入数据
mysql:
conn = pymysql.connect(host=‘localhost‘, user=‘root‘, passwd=‘123456‘,
db=‘mydb‘, port=3306, charset=‘utf8‘)
cursor = conn.cursor() # 光标对象
cursor.execute("insert into students (name,sex,grade) values(%s,%s,%s)",
(‘张三‘, ‘女‘, 87)) # 插入数据
conn.commit()
csv操作:
# csv文件的读取,把csv文件这种的每行数据转化为一个列表
fp = open(‘F:/douban.csv‘, encoding=‘utf-8‘)
reader = csv.reader(fp)
for row in reader:
print(row)
fp.close()
# 转化为字典
fp2 = open(‘F:/douban.csv‘, encoding=‘utf-8‘)
reader2 = csv.DictReader(fp2)
for row in reader2:
print(row)
fp2.close()
标签:mongod pass values 插入 roo ODB har into 连接数据库
原文地址:https://www.cnblogs.com/luoye-guigen/p/12818403.html