How to retrieve data from a MySQL table through Python code?
How to retrieve data from a MySQL table through Python code?
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall
python mysql get column names and values | how to fetch data from sql server database in python | how to fetch data from database in python and display in html table | display data from database in python | python script to run sql query | python mysql select into variable | python mysql fetchall python mysql get column names and values how to fetch data from sql server database in python how to fetch data from database in python and display in html table display data from database in python python script to run sql query python mysql select into variable python mysql fetchall
Share
You can get data OR query data from a MySQL database in Python by using MySQL Connector/Python API such as fetchone() OR fetchall()
Fetch a single row:
row = cursor.fetchone ()
Fetch multiple rows:
data = cursor.fetchall ()
Example code:
import MySQLdb
import sys
connection = MySQLdb.connect (host = "192.168.1.1", user = "root", passwd = " " , db = "data_wirehouse")
cursor = connection.cursor ()
cursor.execute ("select firstname,lastname from user_master")
data = cursor.fetchall ()
for row in data :
print row[0], row[1]
cursor.close ()
connection.close ()
sys.exit()