当前位置:Gxlcms > 数据库问题 > Python3中使用Mysql的用法。

Python3中使用Mysql的用法。

时间:2021-07-01 10:21:17 帮助过:16人阅读

coding utf-8 import pymysql try: conn = pymysql.connect(host=localhost,user="root",password=123456,database=datarepair,port=3306,charset=utf8) cursor = conn.cursor() #cursor.execute("select rowId,Name from ruletab where ruletype=%s",(10)) cursor.executemany("select rowId,Name from ruletab where ruletype=%s",[10,20]) #一般用于批量增删改中。 print(cursor.rowcount,cursor.rownumber) for x in cursor.fetchall(): print("rowId:{0[0]} Name:{0[1]} RowNumber:{1}".format(x,cursor.rownumber)) print(- * 50) for x in cursor.fetchmany(2): print("rowId:{0[0]} Name:{0[1]} RowNumber:{1}".format(x,cursor.rowcount)) print(- * 50) cursor.scroll(0,absolute) #将游标调回0位置处。 for x in cursor.fetchmany(2): #取2条记录。 print("rowId:{0[0]} Name:{0[1]} RowNumber:{1}".format(x,cursor.rownumber)) print(cursor.rowcount,cursor.rownumber) cursor.close() finally: if conn in dir() and callable(conn) and conn.open: conn.close() print("closed successfully.")

 

Python3中使用Mysql的用法。

标签:mysqld   fetch   localhost   local   finally   success   sql   span   记录   

人气教程排行