0% found this document useful (0 votes)
12 views1 page

Code

This document provides a Python script for connecting to a MySQL database using the mysql.connector module. It demonstrates how to execute a query to select all records from a specified table and fetch the results. Finally, it prints the fetched rows and closes the cursor connection.

Uploaded by

praveen kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Code

This document provides a Python script for connecting to a MySQL database using the mysql.connector module. It demonstrates how to execute a query to select all records from a specified table and fetch the results. Finally, it prints the fetched rows and closes the cursor connection.

Uploaded by

praveen kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Get Data From MYSQL Database Using Python

#import mysql module


import mysql.connector

#Connecting to our database


con =
mysql.connector.connect(user='root',password='',host='localhost',database='pyt
hon')

#creating cursor to use its various methods further


cur = con.cursor()

#this is our mysql query


cur.execute("""select * from pytable""")

#It is going to fetch the executed mysql query into rows.


#Hence assigning it to row
row = cur.fetchall()

#printing the result


print row

#closing the function


cur.close()

You might also like