文章详情

短信预约信息系统项目管理师 报名、考试、查分时间动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

setup airflow on MySQL

2016-09-24 22:52

关注


	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

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯