zoukankan      html  css  js  c++  java
  • python操作mysql数据库

    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()
  • 相关阅读:
    Java中的阻塞队列
    大数据笔记
    物联网小笔记
    shell 笔记
    Redis笔记
    rabbitMQ笔记
    java.lang.NoClassDefFoundError: freemarker/template/Template
    分布式系列学习-事务处理
    免费无需破解xshell xftp下载
    idea maven模块变灰或者java文件夹非 Sources文件夹
  • 原文地址:https://www.cnblogs.com/qiaoer1993/p/13667025.html
Copyright © 2011-2022 走看看