از یک جدول را انتخاب کنید(Select From a Table)
برای انتخاب از یک جدول در MySQL، از عبارت "SELECT" استفاده کنید:
مثال
Select all records from the "customers" table, and display the
result:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="youruse
ame",
passwd="yourpassword",
database="mydatabase"
)
mycursor =
mydb.cursor()
mycursor.execute("SELECT * FROM customers")
myresult = mycursor.fetchall()
for x in myresult:
print(x)
توجه: ما از fetchall()
استفاده می کنیم
متد، که تمام ردیفها را از آخرین دستور اجرا شده واکشی میکند.