我正在尝试使用pymysql从mysql数据库中删除一些记录,但是我无法执行。如果我在mysql中执行它的工作,则使用相同的命令。
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Connect to the MYSQL database
logger.info("Connecting to MySQL database")
try:
conn = pymysql.connect(host=rds_host, user=name, passwd=password, database=db_name, cursorclass=pymysql.cursors.DictCursor)
cur = conn.cursor()
except:
logger.error("ERROR: Unexpected error: Could not connect to MySql instance.")
sys.exit()
logger.info("SUCCESS: Connection to MySQL database succeeded")
def _clean_general_logs():
cur.execute(
"DELETE FROM desker.general_log WHERE event_time <= '2019-08-12 04:36:42.457536' ORDER BY event_time DESC limit 10")
conn.commit()
cur.close()
conn.close()
return {"result": True}