Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id();
- #! / 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"
- import pypyodbc
- # Completar <<server>> <<user>> y <<passw>>
- conn = pypyodbc.connect("DRIVER={SQL Server};SERVER=<<server>>;DATABASE=master;UID=<<user>>;PWD=<<passw>>")
- cur = conn.cursor()
- # Este es tu INSERT revisar compatibilidad MySql / MSSQL
- 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)
- cur.commit()
- # Cierro conexión
- conn.close()
- #! / usr / bin / python
- # - * - coding: UTF-8 - * -
- import os, sys
- import signal, os, sys
- import MySQLdb #MySQL
- import pymssql #SQL server 2016
- #Conexión a MySQL
- conexion_mysql = MySQLdb.connect(host = '10.248.204.43', user = 'root', passwd = 'sahc', db = 'Biblioteca')
- #Conexión a SQL Server
- server = "AXPOS10"
- user = "santiago"
- password = "Python@Monitor"
- base = "StoragePython"
- conexion_sql = pymssql.connect(server, user, password, base)
- cur = conexion_mysql.cursor() #Cursor de Mysql
- cur2 = conexion_sql.cursor() #Cursor de SQL Server
- #Consulta a MySQL
- consulta = ('SELECT *, IF(time >= 10,"Bad","Good") AS Estado FROM INFORMATION_SCHEMA.PROCESSLIST WHERE id <> connection_id()')
- cur.execute(consulta) #Ejecución de consulta MySQL apartir del for es ejecución a SQL Server y en el if se ejecuta el comando KILL en MySQL
- 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 LogKillProcesstMySQL 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 '') + "'" + "," + "GETDATE()" + ")"
- cur2.execute(sql) #Ejecución de insertado SQL Server
- conexion_sql.commit()
- print "Datos Guardados Exitosamente"
- if row[0] == row[0]:
- matar = "KILL " + str(row[0])
- cur.execute(matar)
- conexion_mysql.commit()
- print "Datos eliminados"
Add Comment
Please, Sign In to add comment