0% found this document useful (0 votes)
26 views

MySQL - Python Connection-By S Dutta

This Python code connects to a MySQL database, retrieves login history data from a table, stores it in a list, and prints out field names and a record.

Uploaded by

bishwaj
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

MySQL - Python Connection-By S Dutta

This Python code connects to a MySQL database, retrieves login history data from a table, stores it in a list, and prints out field names and a record.

Uploaded by

bishwaj
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import mysql.

connector

rec = []

cnx = mysql.connector.connect(user='ideation', password='Admin@123',


host='127.0.0.1',
database='ideation')
cursor = cnx.cursor()

cursor.execute("select * from login_history")

field_names = [i[0] for i in cursor.description]

for row in cursor:


print (row)
rec.append(row)

cursor.close()
cnx.close()

print(field_names)
print (rec[5][1])

You might also like