Input: Table Name: Products
Columns: product_id, name, price
Output: import mysql.connector
db = mysql.connector.connect(
host=”localhost”,
user=”root”,
passwd=”password”,
database=”dbname”
)
mycursor = db.cursor()
sql = “SELECT product_id, name, price FROM Products”
mycursor.execute(sql)
myresult = mycursor.fetchall()
for row in myresult:
print(row)
Prompt: Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
Generate a Python script for a query to fetch data from a given MySQL table.
### Input:
Table Name: Products
Columns: product_id, name, price
### Output:
import mysql.connector
db = mysql.connector.connect(
host=”localhost”,
user=”root”,
passwd=”password”,
database=”dbname”
)
mycursor = db.cursor()
sql = “SELECT product_id, name, price FROM Products”
mycursor.execute(sql)
myresult = mycursor.fetchall()
for row in myresult:
print(row)