限制查询返回的记录数
- import mysql.connector
- mydb = mysql.connector.connect(
- host="localhost",
- user="myusername",
- passwd="mypassword",
- database="mydatabase"
- )
- mycursor = mydb.cursor()
- mycursor.execute("SELECT * FROM customers LIMIT 5")
- myresult = mycursor.fetchall()
- for x in myresult:
- print(x)