Nov 10, 2018

Sample of using python to call MySQL procedure

MySQL procedure:
DELIMITER $$
CREATE DEFINER=`i88`@`192.168.%` PROCEDURE `test_only`()
BEGIN
select now() as now;
END
Python sample to call the procedure:

'''
@author: it.i88.ca
'''
import MySQLdb

db = MySQLdb.connect(host="yourHost", user="i88.ca", passwd="it.i88.ca", db="i88ca")
#create a cursor for the select
cur = db.cursor()
cur.execute("call test_only();")
results=cur.fetchone()
print results[0]

          #other usage:
          # for row in cur.fetchall() :
          #    print row[0], row[1]
          #    print row
 # close the cursor
cur.close()
# close the connection
db.close ()


The result:
2015-01-17 14:33:49