python sql 批量插入添加数据
发布日期:2021-06-24 15:22:07
浏览次数:2
分类:技术文章
本文共 2041 字,大约阅读时间需要 6 分钟。
import osfrom tinytag import TinyTagimport mysql.connector# database 链接数据库mydb = mysql.connector.connect( host="localhost", user="root", passwd="123456", auth_plugin='mysql_native_password', database="Testdatabase")mycursor = mydb.cursor()#c 创建数据库'''mycursor = mydb.cursor()mycursor.execute("CREATE DATABASE mydatabase")'''#创建表单#mycursor.execute("CREATE TABLE Tname6 (place VARCHAR(255), artist VARCHAR(255), duration VARCHAR(255), album VARCHAR(255), title VARCHAR(255),id INT AUTO_INCREMENT PRIMARY KEY))")#mycursor.execute("CREATE TABLE Tname7 (place VARCHAR(255), artist VARCHAR(255), duration VARCHAR(255), album VARCHAR(255), title VARCHAR(255), id INT AUTO_INCREMENT PRIMARY KEY)")#插入数据sql = "INSERT INTO Tname7 (place, artist,duration,album,title) VALUES (%s, %s, %s, %s,%s)"#val = ("fff", "ssss", "fsdfsdf", "Highway 21", "Highway 21")#批量录入数据path="E:\\KwDownload\\抖音伤感抖音伤感热歌"MusicFileList=[]MusicFileCount=0for root,dirs,files in os.walk(path): for name in files: MusicFileTuple=() if name.endswith(".mp3") or name.endswith(".wav") or name.endswith(".mp4"): print(os.path.join(root,name)) #MusicFileList.append(os.path.join(root,name)) tag = TinyTag.get(os.path.join(root,name)) print(tag.artist) #MusicFileList.append(tag.artist) print(tag.duration) #MusicFileList.append(tag.duration) print(tag.album) #MusicFileList.append(tag.album) print(tag.title) #MusicFileList.append(tag.title) MusicFileTuple=(os.path.join(root,name),tag.artist,tag.duration,tag.album,tag.title) MusicFileCount=MusicFileCount+1 DBval=(str(os.path.join(root,name)),str(tag.artist),str(tag.duration),str(tag.album),str(tag.title)) mycursor.execute(sql,DBval) MusicFileList.append(MusicFileTuple)print(MusicFileCount)print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")print(MusicFileList)print("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&")mydb.commit()print(mycursor.rowcount, "条记录已插入")
转载地址:https://blog.csdn.net/weixin_33595571/article/details/109649788 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月27日 13时21分43秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【机器学习】核函数的理解与常见核函数
2019-04-28
【一次认识一个市场技术指标】之ATR(真实波幅指标)
2019-04-28
【一次认识一个市场技术指标】之RSI(相对强弱指标)
2019-04-28
【一次认识一个市场技术指标】之KDJ(随机指标)
2019-04-28
一文读懂量化系统接入及相关平台
2019-04-28
【vn.py】 策略实盘自动交易
2019-04-28
【机器学习】多元函数梯度的理解
2019-04-28
【金融量化】期货中的对手价、市价、排队价、最新价分别表示什么价位
2019-04-28
【矩阵论】《理解矩阵》学习笔记
2019-04-28
【机器学习】网络表征学习、网络嵌入必读论文
2019-04-28
【机器学习】极大似然估计、最大后验估计的对比与联系
2019-04-28
【机器学习】模糊认知图(Fuzzy Cognitive Map, FCM)概念介绍
2019-04-28
【机器学习】L1、L2正则化项的理解及其在机器学习中的应用
2019-04-28
什么是P问题、NP问题和NPC问题
2019-04-28
【机器学习】最小二乘法的理解
2019-04-28
Python数据可视化之使用GridSpec自定义子图
2019-04-28
使用sklearn进行对数据标准化、归一化以及将数据还原
2019-04-28
Tensorflow中关于参数初始化的方法
2019-04-28
对论文中模型进行编程实现时的注意要求和总结
2019-04-28