#创建套接字 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
defmain():
mysql = pymysql.connect(host=host, user=user, password=password, port=port)
#新建查询页面 cursor = mysql.cursor()
#sql sql = 'select * from rs_datainsight.rs_admin_log where from_unixtime(createtime,\'%Y-%m-%d %H:%i:%s\') between date_format(date_add(now(), interval - 5 minute),\'%Y-%m-%d %H:%i:%s\') and date_format(now(),\'%Y-%m-%d %H:%i:%s\')'
#执行sql cursor.execute(sql)
#返回结果 # result = cursor.fetchone() #返回单条数据 results = cursor.fetchall() #返回多条数据
for result in results: #print(result) #发送到第三方端口 s.sendto(str(result).encode("utf-8"),(OUTPUTIP,OUTPUTPORT))
#关闭查询 cursor.close()
#关闭数据库 mysql.close()
if __name__ == "__main__": whileTrue: main() time.sleep(300) #睡眠五分钟 s.close()