# Migrate SQL Server data to InfluxDB

**URL:** <https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746>\
**Category:** Telegraf\
**Tags:** influxdb\
**Created:** [August 26, 2020, 1:02pm UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746 "2020-08-26T13:02:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torounia](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/torounia/32/5542_2.png) [@Torounia](https://community.influxdata.com/u/Torounia)\
**Post date:** [August 26, 2020, 1:02pm UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746/1 "2020-08-26T13:02:13Z")

</div>

We have a database in SQL Server which I want ultimately migrate to Influxdb. The data is mainly time series.

As a starting point I want to keep both databases for few months while we get confident with Influxdb and then migrate completely.

I build the following code:

```
import pypyodbc 

import pandas as pd

import datetime

import time

import argparse

from influxdb import DataFrameClient

cnxn = pypyodbc.connect("Driver={ODBC Driver 17 for SQL Server};"

                        "Server=example\SQLEXPRESS;"

                        "Database=example;"

                        "uid=example;pwd=example")

cursor = cnxn.cursor()

df = pd.read_sql_query('SELECT TOP (1000) * FROM [something].[dbo].[something]', cnxn)

print(df)

client = DataFrameClient('localhost', 8086)

def convert_timestamps(timestamp):

    return int(time.mktime(datetime.datetime.strptime(timestamp, '%y%m%d%H%M%S').timetuple()))

df['dptimestamp'] = df['dptimestamp'].apply(convert_timestamps)

df['dptimestamp'] = pd.DatetimeIndex(df['dptimestamp'])

df.index = df['dptimestamp']

print(df.index)

print(type(df['dptimestamp']))

print(df)

client.write_points(df, tag_columns={'devicedescription': df['devicedescription']}, database='Occupancy_system', measurement='dpvalue',time_precision='s')

```

I am using the pypyodbc in combination with pandas to query the data into a dataframe and them trying to save to Influxdb using client.write\_points.

Overall I cant make to work and searching online I can see the influx dataframe method is not stable to write back to Influx.

the error I get with the above code is:

```
 raise InfluxDBClientError(err_msg, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"unable to parse following by the dataframe

```

open question:

is there a telegraph plugin to query SQL database and write the data?  
is there any other way to achieve my task to your experience

Influxdb version 1.8

Thanks alot

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 31, 2020, 4:20pm UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746/2 "2020-08-31T16:20:17Z")

</div>

Hello @Torounia,  
Thanks for your question!

Have you considered using the SQL Flux package?

> **[sql package | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/sql/)**
>
> The sql package provides tools for working with data in SQL databases.

---

<div class="post-metadata">

**Author:** ![shnabin](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/shnabin/32/5883_2.png) [@shnabin](https://community.influxdata.com/u/shnabin)\
**Post date:** [November 3, 2020, 5:14pm UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746/3 "2020-11-03T17:14:12Z")

</div>

Hi @Anaisdg ,

I’ve the same need of migrating huge data from SQL server to influxdb, is there any plugin available for this? I went through flux but I was unable to understand the following, can you please clarify

1. Using Influx CLI for flux seems not so smooth, other than chronograf are there anyother IED/tools to use flux?
2. Is Migration of data (I see the Join query) from MSSQL to influxdb possible with flux, can you please provide some examples.

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [November 4, 2020, 9:51pm UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746/4 "2020-11-04T21:51:03Z")

</div>

> **[Flux - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=influxdata.flux)**
>
> Extension for Visual Studio Code - Flux language extension for VSCode

How much data is a huge amount?  
I’m looking into this and I’ll get back to you as soon as I can.

---

<div class="post-metadata">

**Author:** ![shnabin](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/shnabin/32/5883_2.png) [@shnabin](https://community.influxdata.com/u/shnabin)\
**Post date:** [November 12, 2020, 6:40am UTC](https://community.influxdata.com/t/migrate-sql-server-data-to-influxdb/15746/6 "2020-11-12T06:40:28Z")

</div>

Hi @Anaisdg,

SQL server- ~ 2 years of 1-minute data (2 \* 365 \* `1440) rows, 30+colums in each table, approx. 200+ tables.

Is there any plugin in discussion/development that will ease the migration process ? Or as previously asked can we handle data migration in flux, can you please share some examples.
