# Loading historical data from mysql table to influxdb with Telegraf

**URL:** <https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612>\
**Category:** Systems\
**Tags:** influxdb, telegraf\
**Created:** [February 28, 2021, 7:04pm UTC](https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612 "2021-02-28T19:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandra\_D](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/aleksandra_d/32/6809_2.png) [@Aleksandra\_D](https://community.influxdata.com/u/Aleksandra_D)\
**Post date:** [February 28, 2021, 7:04pm UTC](https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612/1 "2021-02-28T19:04:04Z")

</div>

Hello,  
I am new to InfluxDB.  
I am trying to write historical data from mysql table to influxdb. Is there any way to use Telegraf for this case? (I tried but I could write only real-time events from mysql instead of data from my table.)

If not, do you have any ideas how to send historical data to influxdb easily?

Please advise. Thank you!

Regards,  
Aleksandra

---

<div class="post-metadata">

**Author:** ![Franky1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/franky1/32/6666_2.png) [@Franky1](https://community.influxdata.com/u/Franky1)\
**Post date:** [March 1, 2021, 5:36pm UTC](https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612/2 "2021-03-01T17:36:23Z")

</div>

> [@Aleksandra\_D](#):
>
> If not, do you have any ideas how to send historical data to influxdb easily?

As far as I know, there is no input plugin for Telegraf that allows you to import historical data from a MySQL database.

In principle, of course, a timestamp should be available for the entries in the MySQL database.  
What comes to my mind quickly:

1. write a script that exports the data from the MySQL database and saves it in the **influx line protocol** format. The format is quite simple. Then import the file into InfluxDB.
2. write an `inputs.exec` or `inputs.execd` **plugin** for Telegraf that exports the data from the MySQL database
3. without Telegraf, query the MySQL database directly from InfluxDB with **flux** `sql.from()`

The following links as a suggestion:

> **[Write data to InfluxDB | InfluxDB OSS v2 Documentation](https://docs.influxdata.com/influxdb/v2/write-data/)**
>
> Collect and write time series data to InfluxDB Cloud and InfluxDB OSS.

> **[Getting Started: Writing Data to InfluxDB | InfluxData](https://www.influxdata.com/blog/getting-started-writing-data-to-influxdb/)**
>
> This is a beginners tutorial by InfluxData's Anais Dotis-Georgiou that shows you how to write static data in batches to InfluxDB 2.0 using three methods.

> **[sql.from() function | Flux Documentation](https://docs.influxdata.com/influxdb/v2/reference/flux/stdlib/sql/from/)**
>
> sql.from() retrieves data from a SQL data source.

> **[Plugin directory | Telegraf Documentation](https://docs.influxdata.com/telegraf/v1/plugins/)**
>
> Telegraf is a plugin-driven agent that collects, processes, aggregates, and writes metrics. It supports four categories of plugins including input, output, aggregator, and processor. View and search all available Telegraf plugins.

---

<div class="post-metadata">

**Author:** ![Aleksandra\_D](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/aleksandra_d/32/6809_2.png) [@Aleksandra\_D](https://community.influxdata.com/u/Aleksandra_D)\
**Post date:** [March 1, 2021, 9:22pm UTC](https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612/3 "2021-03-01T21:22:38Z")

</div>

Thank You @Franky1 ! You helped me a lot.

---

<div class="post-metadata">

**Author:** ![Mara\_Sitharamane](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mara_sitharamane/32/6797_2.png) [@Mara\_Sitharamane](https://community.influxdata.com/u/Mara_Sitharamane)\
**Post date:** [October 2, 2021, 5:45am UTC](https://community.influxdata.com/t/loading-historical-data-from-mysql-table-to-influxdb-with-telegraf/18612/4 "2021-10-02T05:45:33Z")

</div>

Hi could someone advice me on how to pull data from mysql database using telegraf please. Ideally I would like them to be published on cloud watch.
