python将数据保存到Mysql的示例代码:import mysqldb# connect Mysqlconn = MySQLdb.connect(host= ,user=&nb
import mysqldb# connect Mysql
conn = MySQLdb.connect(
host= ,
user= ,
passwd= ,
db= ,
port= ,
charset='utf8')
cursor = conn.cursor()
filter_merge_len = len(filter_merge_data)
for x in range(filter_merge_len):
try:
cursor.execute(
"insert into database_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()
except Exception as e:
print 'Insert Failed'
# close
conn.commit()
cursor.close()
conn.close()
--结束END--
本文标题: python怎么将数据保存到mysql
本文链接: https://lsjlt.com/news/112078.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0