Python实现airflow任务及时性校验
1、Python连接Mysql数据库,获取版本号:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymysql
# 打开数据库连接
db = pymysql.connect("host_id", "user_name", "password", "db_name", charset='utf8' )
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()
print("Database version : %s " % data)
# 关闭数据库连接
db.close()
2、Python创建Mysql表:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymysql
# 打开数据库连接
db = pymysql.connect("host_id", "user_name", "password", "db_name", charset='utf8' )
# 使用cursor()方法获取操作游标
cursor = db.cursor()
# 使用 execute() 方法执行 SQL,如果表存在则删除
cursor.execute("DROP TABLE IF EXISTS notify_group")
# 使用预处理语句创建表