Airflow默认使用sqllite,测试完成后我需要改成MySQL

Airflow使用MySQL_airflow

具体步骤如下

1.- 安装MySQL Server

sudo apt install mysql-server

sudo systemctl start mysql.service

2.- 创建用户和DB

sudo mysql

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

exit

mysql -u root -p


以下均是在 mysql > 下输入的命令

ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;

CREATE USER 'airflow'@'localhost' IDENTIFIED BY 'airflow';

create database airflow;

GRANT all privileges on airflow.* TO 'airflow'@'localhost';

FLUSH PRIVILEGES;

set explicit_defaults_for_timestamp = 1;


sudo systemctl restart mysql

3.- 安装mysql客户端支持

pip3 install pymysql

4.- 修改airflow配置文件使用mysql

vim ~/airflow/airflow.cfg

executor = LocalExecutor

sql_alchemy_conn = mysql+pymysql://airflow:airflow@127.0.0.1/airflow

5.- 初始化DB

airflow db reset

airflow db init

6.- 重启airflow服务 (参考这篇文章将airflow设为服务:https://blog.51cto.com/helpdesk/6721117)

sudo service airflow-webserver restart

sudo service airflow-scheduler restart

7.- 重新创建airflow用户

airflow users  create --role Admin --username airflow --email admin --firstname admin --lastname admin --password airflow

8.- 登录测试

http://localhost:8080