NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

Airflow笔记-MySqlOperator使用及conn配置 #250

Open NeroCube opened 3 years ago

NeroCube commented 3 years ago

from airflow import DAG from airflow.utils.dates import days_ago from airflow.operators.mysql_operator import MySqlOperator from datetime import datetime, timedelta

default_args = { 'owner': 'Nero Chen', 'depends_on_past': False, 'start_date': datetime(2021, 1, 12, 0, 0), 'email': ['join810316@gmail.com'], 'email_on_failure': True, 'email_on_retry': True, 'retries': 1, 'retry_delay': timedelta(minutes=5), }

dag = DAG( 'test_mysql_operator', default_args=default_args, description='test mysql operator', schedule_interval=" *")

insert_sql = "insert into test(content) values ('{}')".format('test')

task = MySqlOperator( task_id='select_sql', sql=insert_sql, mysql_conn_id='mysql_conn_test', autocommit=True, dag=dag)

task

NeroCube commented 3 years ago
-- phpMyAdmin SQL Dump
-- version 5.0.4
-- https://www.phpmyadmin.net/
--
-- Host: mysql
-- Generation Time: Jan 16, 2021 at 03:26 PM
-- Server version: 5.7.24
-- PHP Version: 7.4.13

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `airflow`
--

-- --------------------------------------------------------

--
-- Table structure for table `test`
--

CREATE TABLE `test` (
  `fid` int(11) NOT NULL,
  `content` text COLLATE utf8_unicode_ci NOT NULL,
  `event_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `creat_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_update_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Indexes for table `test`
--
ALTER TABLE `test`
  ADD PRIMARY KEY (`fid`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `test`
--
ALTER TABLE `test`
  MODIFY `fid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;