首页 > 数据库技术 > 详细

python操作mysql数据库

时间:2020-09-14 16:18:06      阅读:120      评论:0      收藏:0      [点我收藏+]
import pymysql
def connect_mysql():
conn = pymysql.connect("ip", "用户名", "密码", "需要连接的数据库", charset=‘utf8‘)
cursor = conn.cursor()
# sql = """CREATE TABLE `check_kafka_status`(
# `id` INT primary key AUTO_INCREMENT COMMENT ‘ID‘,
# `group_id` varchar(40) COMMENT ‘kafka的group_id‘,
# `code` varchar(4) COMMENT ‘0不变,1增加,-1减少‘,
# `exited` varchar(200) COMMENT ‘已经启动的docker,列表形式‘,
# `adding` varchar(40) COMMENT ‘需要增加的docker‘,
# `reduce` varchar(40) COMMENT ‘需要减少的docker‘,
# `update_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT ‘更新时间‘
# ) ENGINE=InnoDB CHARSET=utf8 COMMENT=‘检测kafka数据积压状态‘;
# """
sql = "insert check_kafka_status (group_id, code) value (‘coupon_update_v1‘, ‘0‘)"
# sql2 = "select exited from check_kafka_status"
try:
cursor.execute(sql)
conn.commit()
# cursor.execute(sql2)
# result = cursor.fetchone()
# print(result)
except Exception as e:
print(e)
conn.rollback()
cursor.close()
conn.close()
if __name__ == ‘__main__‘:
connect_mysql()

python操作mysql数据库

原文:https://www.cnblogs.com/qiaoer1993/p/13667025.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!