Do I need to close cursor every time after mysql conn execution?

get a conn,

multiple commands need to be executed,

do I need to close cursor after executing one sql at a time?

Mar.29,2021

is generally given to the database connection pool to operate the opening and closing of each connection instance
if you get it yourself, it is best to close it at the end of the method execution.


can execute more than one at a time. Use python to raise a chestnut

import MySQLdb as mdb
import sys

conn = mdb.connect(host = 'localhost', user = 'root', passwd = '123456', db = 'test')
 
 cur = conn.cursor()
cur.execute("insert into contact values('key1', 'value1')")
cur.execute("select * from test")
row_num = int(cur.rowcount)
for i in range(row_num):
     row = cur.fetchone()
     print row
 -sharpcommit
 conn.commit()
 cur = conn.cursor()
 conn.close()

this problem is related to the transaction support of MySQL's storage engine. There are many types of storage engines in MySQL, such as: MyISAM, InnoDB and so on. MyISAM does not support transactions, while InnoDB is a transactional database that supports transactions. For example, the InnoDB engine, so the operation of the database data will be done in the pre-allocated cache, only after the commit, the database data will be changed.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ef79-2b9a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ef79-2b9a1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?