ip = config.ip user_name = config.user_name passwd = config.passwd db_name = config.db_name table_name = config.table_name # 更新数据库存原始名 def update_data(original_path, id): try: conn = pymysql.connect(ip, user_name, passwd, db_name, charset='utf8', use_unicode=True) except Exception as e: logging.info('connect fail') logging.error(e) else: sql = 'update %s set original_path="%s" where id=%s' %(table_name, original_path, id) cursor = conn.cursor() try: cursor.execute(sql) conn.commit() logging.info('update db ok') except Exception as e: logging.error(e) conn.rollback() else: conn.close()