python怎么将数据保存到mysql
python将数据保存到mysql的示例代码:
importMySQLdb#connectMySQL
conn=MySQLdb.connect(
host=,
user=,
passwd=,
db=,
port=,
charset='utf8')
cursor=conn.cursor()
filter_merge_len=len(filter_merge_data)
forxinrange(filter_merge_len):
try:
cursor.execute(
"insertintodatabase_name.table_name(date,monitor_item,host_ip,cluster\
,software,alarm_hit)values('%s','%s','%s','%s','%s','%d')"%
(yest_date,filter_merge_data.iloc[:,0][x],
filter_merge_data.iloc[:,1][x],
filter_merge_data.iloc[:,2][x],
filter_merge_data.iloc[:,3][x],
filter_merge_data.iloc[:,4][x]))
#提交到数据库执行
conn.commit()
exceptExceptionase:
print'InsertFailed'
#close
conn.commit()
cursor.close()
conn.close()
下一篇:redis是什么数据库模型
python mysql数据库 msql
声卡驱动正常但是没有声音如何办?声卡驱动正常没声音的解决方法
英伟达显卡驱动如何退回到原来版本?英伟达显卡驱动退回到原来版
重装系统,电脑只有一个C盘如何创建分区
Defender提示错误应用程序MsMpEng.exe无法启动
电脑无法启动或仍在加载如何办?电脑无法启动或仍在加载的解决方
打印机驱动如何卸载删除?卸载打印机驱动干净的教程
电脑没网如何安装网卡驱动?教你没网如何安装网卡驱动的方法
系统32位和62位如何选择:详解它们之间的差异
电脑文件删不掉如何办?四种方法解决
任务管理器快捷键有哪些?任务管理器快捷键大全