0

Good day I have a doubt, I have a code generated in Python which he does is to query a MySQL table named INFORMATION_SCHEMA.PROCESSLIST as follows:

SELECT *, IF (time> = 10, "Bad", "Good") AS State FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id ();

Once this fulfills my conditions by means of python code I tell you to save those processes and also kill them with the command KILL, but the data that I send to make them in a table that creates in MySQL.

Now what I want is to continue browsing in MySQl, but I want to know if there is any way to save the queried data to a table but to SQL Server, basically query MySQL and save it to SQL Server.

Annex the code:

#! / Usr / bin / python
# - * - coding: UTF-8 - * -
Import os, sys
Import signal, os, sys
Import MySQLdb
connection_mysql = MySQLdb.connect (host = '10 .248.204.43 ', user =' root ', passwd =' sahc ', db =' Library ')

cur = conexion_mysql.cursor ()
query = ('SELECT *, IF (time> = 10,' Bad ',' Good ') AS State FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id ()')
cur.execute (query)
for row in cur.fetchall ():
    result = row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]
    sql = "INSERT INTO test VALUES (" + str (row [0]) + "," + "'" + (row [1] or' ') + "'" + "," + " [2] or "+", "+", "+", "+ (row [3] or '') +" '"+", "+" ) + "," + "," + "," + ", +", "+", "(Row [6] or '') [7] or '') + "'" + "," + "now ()" + ")"
    cur.execute (sql)
    connection_mysql.commit ()
    print "Successfully Saved Data"
    if row [0] == row [0]:
        kill = "KILL" + str (row [0])
        cur.execute
        connection_mysql.commit ()
        print "Deleted data"

As you consult and save in MySQL, I want to continue browsing in MySQL but save the data in SQL Server.

I would appreciate the help :)

2
  • Do you want to bring the results into your Python program, then store them in MS SQL? Or do you want to store the results of the MySQL query in MS SQL without having to bring the results into your Python program?
    – RDFozz
    Jun 8, 2017 at 18:11
  • >>Or do you want to store the results of the MySQL query in MS SQL without having to bring the results in your Python program? Exactly I want to send the query and save in SQL Server without tner that bring results to my application :) Jun 8, 2017 at 19:58

1 Answer 1

-1

There is an option in MSSQL called linked server, where you can connect to MySQL server by using MSSQL queries. So you can query data from MSSQL linked server (MySQL data) and insert data into MSSQL.

I hope this works for your query. Give a try.

2
  • Ok, I check now :) Jun 8, 2017 at 17:06
  • Since you want to write the MySQL data into MS SQL Server without bringing it to your application first, a linked server is actually a good solution.
    – RDFozz
    Jun 8, 2017 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.