标签:连接 mysql存储 cursor host connect 调用 user iter 回收
1.简单示例
delimiter || CREATE PROCEDURE p1( in n1 int, out n2 int ) BEGIN set n2=123; SELECT * FROM student WHERE stid>n1; END|| delimiter ; set @v1=0 call p1(10,@v1) SELECT @v1;
pymysql调用
import pymysql # 创建连接 conn = pymysql.connect(host=‘192.168.224.161‘, port=3306, user=‘root‘, passwd=‘123456‘, db=‘test‘, charset=‘utf8‘) # 创建游标 cursor = conn.cursor() # 执行SQL,并返回收影响行数 cursor.callproc("p1",(3,4)) #4为out参数 r1=cursor.fetchall() print(r1) cursor.execute("select @_p1_0,@_p1_1") r2=cursor.fetchall() #输出((3, 123),) print(r2) # 关闭游标 cursor.close() # 关闭连接 conn.close()
标签:连接 mysql存储 cursor host connect 调用 user iter 回收
原文地址:https://www.cnblogs.com/hbxZJ/p/9561831.html