I have a list of column names that I want to pull from a mysql database. It is good practice to loop through it and query each time?
When I do this, sometimes/randomly it seems to hang; when I restart the script, it hangs at different iterations. Was wondering whether this is bad practice to do in the first place before I continue trying to decipher what's the issue.
import mysql.connector
import numpy as np
cnx = mysql.connector.connect(user='user', password='pw', host='ip_here')
for i,j in enumerate(columnList):
cursor.execute('SELECT `' + j + '` FROM `table_name`')
iValues = cursor.fetchall()
cursor.close
if i == 0:
extractedValues = iValues
else:
extractedValues = np.hstack((extractedValues, iValues))
cnx.close