iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 > setup airflow on MySQL
  • 745
分享到

setup airflow on MySQL

摘要

sqlite Database https://airflow.apache.org/docs/apache-airflow/stable/howto/set-up-database.html#setting-up-a-sqlite-dat


	setup airflow on MySQL
[数据库教程]

sqlite Database

https://airflow.apache.org/docs/apache-airflow/stable/howto/set-up-database.html#setting-up-a-sqlite-database

用于开发环境,有一些限制,只支持 序列执行器, 不能用作产品环境。

SQLite database can be used to run Airflow for development purpose as it does not require any database server (the database is stored in a local file). There are a few limitations of using the SQLite database (for example it only works with Sequential Executor) and it should NEVER be used for production.

 

Mysql Database

Https://airflow.apache.org/docs/apache-airflow/stable/howto/set-up-database.html#setting-up-a-mysql-database

先建立数据库

You need to create a database and a database user that Airflow will use to access this database. In the example below, a database airflow_db and user with username airflow_user with passWord airflow_pass will be created

CREATE DATABASE airflow_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER ‘airflow_user‘ IDENTIFIED BY ‘airflow_pass‘;
GRANT ALL PRIVILEGES ON airflow_db.* TO ‘airflow_user‘;

 

设置数据库配置文件  explicit_defaults_for_timestamp=1

We rely on more strict ANSI SQL settings for MySQL in order to have sane defaults. Make sure to have specified explicit_defaults_for_timestamp=1 option under [mysqld] section in your my.cnf file. You can also activate these options with the --explicit-defaults-for-timestamp switch passed to mysqld executable

 

安装python的客户端驱动库

pip install mysqlclient

We recommend using the mysqlclient driver and specifying it in your SqlAlchemy connection string.

 

设置DATABASE_URI

https://airflow.apache.org/docs/apache-airflow/stable/howto/set-up-database.html#database-uri

修改 airflow.cfg配置文件中的 sql_alchemy_conn 参数,或者配置环境变量AIRFLOW__CORE__SQL_ALCHEMY_CONN

Airflow uses SQLAlchemy to connect to the database, which requires you to configure the Database URL. You can do this in option sql_alchemy_conn in section [core]. It is also common to configure this option with AIRFLOW__CORE__SQL_ALCHEMY_CONN environment variable.


mysql+mysqldb://:@[:]/

 

初始化数据库

https://stackoverflow.com/questions/61663681/configure-sql-server-in-airflow-with-sql-alchemy-conn

airflow initdb

 

另外一种客户端驱动

支持SSL免证书选项。

But we also support the mysql-connector-Python driver, which lets you connect through SSL without any cert options provided.

mysql+mysqlconnector://:@[:]/

 

 

客户端驱动issue

如果驱动未安装或者安装不正确, 执行 airflow initdb 会报错

ModuleNotFoundError: No module named ‘MySQLdb‘

解决办法就是使用pip安装相应的驱动。

https://stackoverflow.com/questions/51245121/mysqldb-modulenotfounderror

 

Database Urls of SQLAlchemy

https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls

The create_engine() function produces an Engine object based on a URL. These URLs follow RFC-1738, and usually can include username, password, hostname, database name as well as optional keyword arguments for additional configuration. In some cases a file path is accepted, and in others a “data source name” replaces the “host” and “database” portions. The typical fORM of a database URL is:

dialect+driver://username:password@host:port/database

Dialect names include the identifying name of the SQLAlchemy dialect, a name such as sqlite, mysql, postgresql, oracle, or mssql. The drivername is the name of the DBapi to be used to connect to the database using all lowercase letters. If not specified, a “default” DBAPI will be imported if available - this default is typically the most widely known driver available for that backend.

 

The MySQL dialect uses mysql-python as the default DBAPI. There are many MySQL DBAPIs available, including MySQL-connector-python and OurSQL:

# default
engine = create_engine(‘mysql://scott:tiger@localhost/foo‘)

# mysqlclient (a maintained fork of MySQL-Python)
engine = create_engine(‘mysql+mysqldb://scott:tiger@localhost/foo‘)

# PyMySQL
engine = create_engine(‘mysql+pymysql://scott:tiger@localhost/foo‘)

 

Excercise

https://GitHub.com/fanqingsong/Machine_learning_workflow_on_airflow

基于本地的调测环境,将此项目改造为基于MySQL数据库后台, 并在readme中记录过程。

 

setup airflow on MySQL

原文地址:https://www.cnblogs.com/lightsong/p/14972493.html

您可能感兴趣的文档:

--结束END--

本文标题: setup airflow on MySQL

本文链接: https://www.lsjlt.com/news/8546.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • sql怎么查看表的索引
    通过查询系统表,可以获取表的索引信息,包括索引名称、是否唯一、索引类型、索引列和行数。常用系统表有:mysql 的 information_schema.statistics、postg...
    99+
    2024-05-14
    mysql oracle
  • sql怎么查看索引
    您可以使用 sql 通过以下方法查看索引:show indexes 语句:显示表中定义的索引列表及其信息。explain 语句:显示查询计划,其中包含用于执行查询的索引。informat...
    99+
    2024-05-14
  • sql怎么查看存储过程
    如何查看 sql 存储过程的源代码:使用 show create procedure 语句直接获取创建脚本。查询 information_schema.routines 表的 routi...
    99+
    2024-05-14
  • sql怎么查看视图表
    要查看视图表,可以使用以下步骤:使用 select 语句获取视图中的数据。使用 desc 语句查看视图的架构。使用 explain 语句分析视图的执行计划。使用 dbms 提供...
    99+
    2024-05-14
    oracle python
  • sql怎么查看创建的视图
    可以通过sql查询查看已创建的视图,具体步骤包括:连接到数据库并执行查询select * from information_schema.views;查询结果将显示视图的名称、...
    99+
    2024-05-14
    mysql
  • sql怎么用循环语句实现查询
    可以通过 do 和 while 语句创建循环,并在循环内执行查询,详细步骤包括:定义循环变量设置循环初始值循环执行查询更新循环变量执行查询循环退出条件 SQL 中使用循环语句实现查询 ...
    99+
    2024-05-14
  • sql怎么用代码修改表中数据
    通过 sql 代码修改表中数据的方法包括:修改单个记录:使用 update 语句设置列值并指定条件。修改多条记录:在 update 语句中指定多个条件来修改满足条件的所有记录。增加新列:...
    99+
    2024-05-14
  • sql怎么用命令创建数据库
    在 sql 中使用 create database 命令创建新数据库,其语法包含以下步骤:指定数据库名称。指定数据库文件和日志文件的位置(可选)。指定数据库大小、最大大小和文件增长(可选...
    99+
    2024-05-14
  • sql怎么用身份证提取年龄
    sql 中提取身份证号码中的年龄的方法:提取出生日期部分(身份证号码中第 7-14 位);使用 to_date 函数转换为日期格式;使用 extract 函数计算与当前日期之间的年差。 ...
    99+
    2024-05-14
  • sql怎么看字段长度
    有两种方法可查看 sql 中的字段长度:使用 information_schema 架构,其中包含元数据信息,可用于查询字段长度。使用内建函数,如 length(),其适用于字符串数据类...
    99+
    2024-05-14
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作