Skip to content
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Logo
  1. ioBroker Community Home
  2. Deutsch
  3. ioBroker Allgemein
  4. Frage : Migrate MySQL nach Influxdb

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.1k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    1.8k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    15
    1
    2.1k

Frage : Migrate MySQL nach Influxdb

Scheduled Pinned Locked Moved ioBroker Allgemein
151 Posts 31 Posters 25.7k Views 25 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JackGruberJ JackGruber

    @MezzoDO ok, das ack feld ist bereits als boolen angelegt, kommt nun aber als int.
    Ihc könnte es anpassen, dass dies beim import convertiert wird.

    M Offline
    M Offline
    MezzoDO
    wrote on last edited by MezzoDO
    #35

    @JackGruber said in Frage : Migrate MySQL nach Influxdb:

    @MezzoDO ok, das ack feld ist bereits als boolen angelegt, kommt nun aber als int.
    Ihc könnte es anpassen, dass dies beim import convertiert wird.

    Das wäre grandios 🙂
    Mein Script, was ich einsetze:

    ### MySQL DB info ###
    #import MySQLdb
    import pymysql
    conn = pymysql.connect(host="localhost",  # your host, usually localhost
                         user="xxx",         # your username
                         passwd="xxx",  # your password
                         db="iobroker")        # name of the data base
     
     
    ### PostgreSQL DB info ###
    import psycopg2
    import psycopg2.extras
     
    #####
    # connection data for PostgreSQL
    #conn = psycopg2.connect("dbname=xxx user=xxx password=xxx host=xxx.xxx.xxx.xxx port =5432")
    #####
     
    # InfluxDB info #
    from influxdb import InfluxDBClient
    #
    #####connection data for InfluxDB#####
    influxClient = InfluxDBClient(host='localhost', port=8086, username='xxx', password='xxx', database='iobroker')
    #####
    #influxClient.delete_database(influx_db_name)
    #influxClient.create_database(influx_db_name)
     
    # dictates how columns will be mapped to key/fields in InfluxDB
    schema = {
        "time_column": "time", # the column that will be used as the time stamp in influx
        "columns_to_fields" : ["ack","q", "from","value"], # columns that will map to fields 
        # "columns_to_tags" : ["",...], # columns that will map to tags
        "table_name_to_measurement" : "name", # table name that will be mapped to measurement
        }
     
    '''
    Generates an collection of influxdb points from the given SQL records
    '''
    def generate_influx_points(records):
        influx_points = []
        for record in records:
            #tags = {}, 
            fields = {}
            #for tag_label in schema['columns_to_tags']:
            #   tags[tag_label] = record[tag_label]
            for field_label in schema['columns_to_fields']:
                fields[field_label] = record[field_label]
            influx_points.append({
                "measurement": record[schema['table_name_to_measurement']],
                #"tags": tags,
                "time": record[schema['time_column']],
                "fields": fields
            })
        return influx_points
     
     
     
    # query relational DB for all records
    #curr = conn.cursor('cursor', cursor_factory=psycopg2.extras.RealDictCursor)
    curr = conn.cursor(cursor=pymysql.cursors.DictCursor) 
    # curr = conn.cursor(dictionary=True)
    #####
    # SQL query for PostgreSQL, syntax for MySQL differs
    # query provide desired columns as a view on the sql server
     
    # request data from SQL, adjust ...from <view name>
    curr.execute("Select * from InfluxData;")
    #####
    row_count = 0
    # process 1000 records at a time
    while True:
        print("Processing row #" + str(row_count + 1))
        selected_rows = curr.fetchmany(1000)
        influxClient.write_points(generate_influx_points(selected_rows))
        row_count += 1000
        if len(selected_rows) < 1000:
            break
    conn.close()
     
    
    JackGruberJ 1 Reply Last reply
    0
    • M MezzoDO

      @JackGruber said in Frage : Migrate MySQL nach Influxdb:

      @MezzoDO ok, das ack feld ist bereits als boolen angelegt, kommt nun aber als int.
      Ihc könnte es anpassen, dass dies beim import convertiert wird.

      Das wäre grandios 🙂
      Mein Script, was ich einsetze:

      ### MySQL DB info ###
      #import MySQLdb
      import pymysql
      conn = pymysql.connect(host="localhost",  # your host, usually localhost
                           user="xxx",         # your username
                           passwd="xxx",  # your password
                           db="iobroker")        # name of the data base
       
       
      ### PostgreSQL DB info ###
      import psycopg2
      import psycopg2.extras
       
      #####
      # connection data for PostgreSQL
      #conn = psycopg2.connect("dbname=xxx user=xxx password=xxx host=xxx.xxx.xxx.xxx port =5432")
      #####
       
      # InfluxDB info #
      from influxdb import InfluxDBClient
      #
      #####connection data for InfluxDB#####
      influxClient = InfluxDBClient(host='localhost', port=8086, username='xxx', password='xxx', database='iobroker')
      #####
      #influxClient.delete_database(influx_db_name)
      #influxClient.create_database(influx_db_name)
       
      # dictates how columns will be mapped to key/fields in InfluxDB
      schema = {
          "time_column": "time", # the column that will be used as the time stamp in influx
          "columns_to_fields" : ["ack","q", "from","value"], # columns that will map to fields 
          # "columns_to_tags" : ["",...], # columns that will map to tags
          "table_name_to_measurement" : "name", # table name that will be mapped to measurement
          }
       
      '''
      Generates an collection of influxdb points from the given SQL records
      '''
      def generate_influx_points(records):
          influx_points = []
          for record in records:
              #tags = {}, 
              fields = {}
              #for tag_label in schema['columns_to_tags']:
              #   tags[tag_label] = record[tag_label]
              for field_label in schema['columns_to_fields']:
                  fields[field_label] = record[field_label]
              influx_points.append({
                  "measurement": record[schema['table_name_to_measurement']],
                  #"tags": tags,
                  "time": record[schema['time_column']],
                  "fields": fields
              })
          return influx_points
       
       
       
      # query relational DB for all records
      #curr = conn.cursor('cursor', cursor_factory=psycopg2.extras.RealDictCursor)
      curr = conn.cursor(cursor=pymysql.cursors.DictCursor) 
      # curr = conn.cursor(dictionary=True)
      #####
      # SQL query for PostgreSQL, syntax for MySQL differs
      # query provide desired columns as a view on the sql server
       
      # request data from SQL, adjust ...from <view name>
      curr.execute("Select * from InfluxData;")
      #####
      row_count = 0
      # process 1000 records at a time
      while True:
          print("Processing row #" + str(row_count + 1))
          selected_rows = curr.fetchmany(1000)
          influxClient.write_points(generate_influx_points(selected_rows))
          row_count += 1000
          if len(selected_rows) < 1000:
              break
      conn.close()
       
      
      JackGruberJ Offline
      JackGruberJ Offline
      JackGruber
      wrote on last edited by
      #36

      @MezzoDO

      Ersetze in deinem Script Zeile 47 mit folgenden zwei zeilen. Auf das einrücken achten!:

                  if field_label == "ack":
                      record[field_label] = bool(record[field_label])
      
      simatecS 1 Reply Last reply
      0
      • JackGruberJ JackGruber

        @MezzoDO

        Ersetze in deinem Script Zeile 47 mit folgenden zwei zeilen. Auf das einrücken achten!:

                    if field_label == "ack":
                        record[field_label] = bool(record[field_label])
        
        simatecS Offline
        simatecS Offline
        simatec
        Developer Most Active
        wrote on last edited by
        #37

        @JackGruber
        Ich komme leider auch nicht weiter ...
        Habe deinen Script von Github installiert und bekomme folgende Ausgabe:

        pi@raspberrypi:~/iobroker_mysql_2_influxdb $ python3 migrate.py all
        Migrate 'all' datapoint(s) ...
        
        Total metrics in ts_number: 0
        Total metrics in ts_bool: 0
        Total metrics in ts_string: 0
        Migrated: 0
        
        

        Das ganze passiert innerhalb einer Sekunde .

        Die Influxdb habe ich über den iobroker Adapter angelegt.

        • Besuche meine Github Seite
        • Beitrag hat geholfen oder willst du mich unterstützen
        • HowTo Restore ioBroker
        JackGruberJ 1 Reply Last reply
        0
        • simatecS simatec

          @JackGruber
          Ich komme leider auch nicht weiter ...
          Habe deinen Script von Github installiert und bekomme folgende Ausgabe:

          pi@raspberrypi:~/iobroker_mysql_2_influxdb $ python3 migrate.py all
          Migrate 'all' datapoint(s) ...
          
          Total metrics in ts_number: 0
          Total metrics in ts_bool: 0
          Total metrics in ts_string: 0
          Migrated: 0
          
          

          Das ganze passiert innerhalb einer Sekunde .

          Die Influxdb habe ich über den iobroker Adapter angelegt.

          JackGruberJ Offline
          JackGruberJ Offline
          JackGruber
          wrote on last edited by
          #38

          Hi @simatec, hab einen mini Fehler im Script gefunden. Durch einen BUG musste das ALL großgeschrieben werden.
          Hab das Script angepasst, einfach neu herunterladen oder das ALL großschreiben.

          simatecS 1 Reply Last reply
          0
          • JackGruberJ JackGruber

            Hi @simatec, hab einen mini Fehler im Script gefunden. Durch einen BUG musste das ALL großgeschrieben werden.
            Hab das Script angepasst, einfach neu herunterladen oder das ALL großschreiben.

            simatecS Offline
            simatecS Offline
            simatec
            Developer Most Active
            wrote on last edited by
            #39

            @JackGruber
            Danke für den Tipp ... Ich hatte es auch einzeln versucht und dann auch jedes Objekt einzeln importiert.
            War zwar etwas Aufwand aber ging super 😉

            • Besuche meine Github Seite
            • Beitrag hat geholfen oder willst du mich unterstützen
            • HowTo Restore ioBroker
            1 Reply Last reply
            0
            • B Offline
              B Offline
              base
              wrote on last edited by
              #40

              Wie und wo kann ich das Script benutzen? In iobroker javascript oder Konsole? iobroker läuft bei mir im Docker Container....

              JackGruberJ 1 Reply Last reply
              0
              • B base

                Wie und wo kann ich das Script benutzen? In iobroker javascript oder Konsole? iobroker läuft bei mir im Docker Container....

                JackGruberJ Offline
                JackGruberJ Offline
                JackGruber
                wrote on last edited by
                #41

                @base python auf deinem PC installieren, das script wie auf der git seite beschrieben installieren und benutzen.

                B 1 Reply Last reply
                0
                • JackGruberJ JackGruber

                  @base python auf deinem PC installieren, das script wie auf der git seite beschrieben installieren und benutzen.

                  B Offline
                  B Offline
                  base
                  wrote on last edited by
                  #42

                  @JackGruber

                  ich bekomme in diese Zeile einen Syntax Error:

                              print(f"Processing row {processed_rows + 1:,} to {processed_rows + len(selected_rows):,} from LIMIT {start_row:,} / {start_row + query_max_rows:,} " + table + " - " + metric['name'] + " (" + str(metric_nr) + "/" + str(metric_count) + ")")
                  

                  er meckert die Anführungsstriche vor table an

                  simatecS JackGruberJ 2 Replies Last reply
                  0
                  • B base

                    @JackGruber

                    ich bekomme in diese Zeile einen Syntax Error:

                                print(f"Processing row {processed_rows + 1:,} to {processed_rows + len(selected_rows):,} from LIMIT {start_row:,} / {start_row + query_max_rows:,} " + table + " - " + metric['name'] + " (" + str(metric_nr) + "/" + str(metric_count) + ")")
                    

                    er meckert die Anführungsstriche vor table an

                    simatecS Offline
                    simatecS Offline
                    simatec
                    Developer Most Active
                    wrote on last edited by
                    #43

                    @base
                    So war es bei mir auch.
                    Hast du mal versucht, die Daten einzeln pro Objekt zu importieren? Das half bei mir.

                    • Besuche meine Github Seite
                    • Beitrag hat geholfen oder willst du mich unterstützen
                    • HowTo Restore ioBroker
                    B 1 Reply Last reply
                    0
                    • simatecS simatec

                      @base
                      So war es bei mir auch.
                      Hast du mal versucht, die Daten einzeln pro Objekt zu importieren? Das half bei mir.

                      B Offline
                      B Offline
                      base
                      wrote on last edited by base
                      #44

                      @simatec habe dein Script von oben ausprobiert, dass holt aber nicht alle Objekte...
                      was muss ich da ändern?

                      ok, habs gefunden. Muss natürlich die SQL Abfrage anpassen. Jetzt klappts

                      1 Reply Last reply
                      0
                      • B base

                        @JackGruber

                        ich bekomme in diese Zeile einen Syntax Error:

                                    print(f"Processing row {processed_rows + 1:,} to {processed_rows + len(selected_rows):,} from LIMIT {start_row:,} / {start_row + query_max_rows:,} " + table + " - " + metric['name'] + " (" + str(metric_nr) + "/" + str(metric_count) + ")")
                        

                        er meckert die Anführungsstriche vor table an

                        JackGruberJ Offline
                        JackGruberJ Offline
                        JackGruber
                        wrote on last edited by
                        #45

                        @base was für eine python version nutzt du?
                        Bei mir läuft das script ohne probleme durch.
                        76e399c7-9eab-47d9-86d5-cef5e7130421-grafik.png

                        B 1 Reply Last reply
                        0
                        • JackGruberJ JackGruber

                          @base was für eine python version nutzt du?
                          Bei mir läuft das script ohne probleme durch.
                          76e399c7-9eab-47d9-86d5-cef5e7130421-grafik.png

                          B Offline
                          B Offline
                          base
                          wrote on last edited by
                          #46

                          @JackGruber hab jetzt Version 3.7.9, hatte vorher 3.9, da ging gar nichts.

                          Den Befehl pip install -r requirements.txt habe ich in der Eingabeaufforderung im entsprechenden Ordner durchgeführt, war das so richtig?

                          JackGruberJ 1 Reply Last reply
                          0
                          • B base

                            @JackGruber hab jetzt Version 3.7.9, hatte vorher 3.9, da ging gar nichts.

                            Den Befehl pip install -r requirements.txt habe ich in der Eingabeaufforderung im entsprechenden Ordner durchgeführt, war das so richtig?

                            JackGruberJ Offline
                            JackGruberJ Offline
                            JackGruber
                            wrote on last edited by
                            #47

                            @base Ja, genau, dann sollte er alle nötigen module installieren.
                            Hm, muss ich mir mal mit python 3.9 anschauen ...

                            B 2 Replies Last reply
                            0
                            • JackGruberJ JackGruber

                              @base Ja, genau, dann sollte er alle nötigen module installieren.
                              Hm, muss ich mir mal mit python 3.9 anschauen ...

                              B Offline
                              B Offline
                              base
                              wrote on last edited by
                              #48

                              @JackGruber wie gesagt, 3.9 hat gar nicht funktioniert bei mir und bei der 3.7.9 bekomme ich die Fehlermeldung

                              1 Reply Last reply
                              0
                              • JackGruberJ JackGruber

                                @base Ja, genau, dann sollte er alle nötigen module installieren.
                                Hm, muss ich mir mal mit python 3.9 anschauen ...

                                B Offline
                                B Offline
                                base
                                wrote on last edited by
                                #49

                                @JackGruber Habe gerade festgestellt, dass die Fehlermeldung nur bei der 64bit Version kommt.
                                Bei der 32èr gehts.
                                Leider bekomme ich jetzt noch einen:

                                MySQL connection error
                                '192.168.1.100'

                                JackGruberJ 1 Reply Last reply
                                0
                                • B base

                                  @JackGruber Habe gerade festgestellt, dass die Fehlermeldung nur bei der 64bit Version kommt.
                                  Bei der 32èr gehts.
                                  Leider bekomme ich jetzt noch einen:

                                  MySQL connection error
                                  '192.168.1.100'

                                  JackGruberJ Offline
                                  JackGruberJ Offline
                                  JackGruber
                                  wrote on last edited by
                                  #50

                                  @base hm komisch grad mit Python 3.9 64 bit getetet und geht 1a.
                                  Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]

                                  Das ist die ganze Fehlerausgabe?

                                  B 1 Reply Last reply
                                  0
                                  • JackGruberJ JackGruber

                                    @base hm komisch grad mit Python 3.9 64 bit getetet und geht 1a.
                                    Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]

                                    Das ist die ganze Fehlerausgabe?

                                    B Offline
                                    B Offline
                                    base
                                    wrote on last edited by
                                    #51

                                    @JackGruber ja

                                    RESTART: C:\Users\Base\Downloads\iobroker_mysql_2_influxdb-master\iobroker_mysql_2_influxdb-master\migrate.py
                                    MySQL connection error
                                    '192.168.1.100'

                                    JackGruberJ 1 Reply Last reply
                                    0
                                    • B base

                                      @JackGruber ja

                                      RESTART: C:\Users\Base\Downloads\iobroker_mysql_2_influxdb-master\iobroker_mysql_2_influxdb-master\migrate.py
                                      MySQL connection error
                                      '192.168.1.100'

                                      JackGruberJ Offline
                                      JackGruberJ Offline
                                      JackGruber
                                      wrote on last edited by
                                      #52

                                      @base teste doch mal in einer powershell folgendes:

                                      Test-NetConnection 192.168.1.100 -p 3307

                                      B 2 Replies Last reply
                                      0
                                      • JackGruberJ JackGruber

                                        @base teste doch mal in einer powershell folgendes:

                                        Test-NetConnection 192.168.1.100 -p 3307

                                        B Offline
                                        B Offline
                                        base
                                        wrote on last edited by
                                        #53

                                        @JackGruber Lernen Sie das neue plattformübergreifende PowerShell kennen – https://aka.ms/pscore6 PS C:\Users\Base> Test-NetConnection 192.168.1.100 -p 3307 WARNUNG: TCP connect to (192.168.1.100 : 3307) failed
                                        ComputerName : 192.168.1.100
                                        RemoteAddress : 192.168.1.100
                                        RemotePort : 3307
                                        InterfaceAlias : WiFi
                                        SourceAddress : 192.168.1.72
                                        PingSucceeded : True
                                        PingReplyDetails (RTT) : 6 ms
                                        TcpTestSucceeded : False

                                        1 Reply Last reply
                                        0
                                        • JackGruberJ JackGruber

                                          @base teste doch mal in einer powershell folgendes:

                                          Test-NetConnection 192.168.1.100 -p 3307

                                          B Offline
                                          B Offline
                                          base
                                          wrote on last edited by
                                          #54

                                          @JackGruber PS C:\Users\Base> Test-NetConnection 192.168.1.100 -p 3306 ComputerName : 192.168.1.100
                                          RemoteAddress : 192.168.1.100
                                          RemotePort : 3306
                                          InterfaceAlias : WiFi
                                          SourceAddress : 192.168.1.72
                                          TcpTestSucceeded : True

                                          PS C:\Users\Base>

                                          JackGruberJ 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate
                                          FAQ Cloud / IOT
                                          HowTo: Node.js-Update
                                          HowTo: Backup/Restore
                                          Downloads
                                          BLOG

                                          730

                                          Online

                                          32.4k

                                          Users

                                          81.4k

                                          Topics

                                          1.3m

                                          Posts
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Recent
                                          • Tags
                                          • Unread 0
                                          • Categories
                                          • Unreplied
                                          • Popular
                                          • GitHub
                                          • Docu
                                          • Hilfe