Good morning I have a doubt, I have a code generated in Python which what it does is to consult a MySQL table named INFORMATION_SCHEMA.PROCESSLIST
in the following way:
SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id();
Once this fulfills my conditions by means of python code, I tell it to save those processes and also kill them with the KILL
command, but the data I send to save is in a table that creates in MySQL .
Now what I want is to continue consulting MySQL, but I want to know if there is a way to save the data queried in a table but SQL Server, basically consult MySQL and save in SQL Server.
Annex the code:
#! / usr / bin / python
# - * - coding: UTF-8 - * -
import os, sys
import signal, os, sys
import MySQLdb
conexion_mysql = MySQLdb.connect(host = '10.248.204.43', user = 'root', passwd = 'sahc', db = 'Biblioteca')
cur = conexion_mysql.cursor()
consulta = ('SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id()')
cur.execute(consulta)
for row in cur.fetchall():
resultado = row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8]
sql = "INSERT INTO prueba VALUES (" + str(row[0]) + "," + "'" + (row[1] or '') + "'" + "," + "'" + (row[2] or '') + "'" + "," + "'" + (row[3] or '') + "'" + "," + "'" + (row[4] or '') + "'" + "," + str(row[5]) + "," + "'" + (row[6] or '') + "'" + "," + "'" + (row[7] or '') + "'" + "," + "now()" + ")"
cur.execute(sql)
conexion_mysql.commit()
print "Datos Guardados Exitosamente"
if row[0] == row[0]:
matar = "KILL " + str(row[0])
cur.execute(matar)
conexion_mysql.commit()
print "Datos eliminados"
As you can see, I keep in MySQL, I want to continue consulting in MySQL but save the data in SQL Server.
I would appreciate the help:)