限制查询返回的记录数

  1. import mysql.connector
  2.  
  3. mydb = mysql.connector.connect(
  4. host="localhost",
  5. user="myusername",
  6. passwd="mypassword",
  7. database="mydatabase"
  8. )
  9.  
  10. mycursor = mydb.cursor()
  11.  
  12. mycursor.execute("SELECT * FROM customers LIMIT 5")
  13.  
  14. myresult = mycursor.fetchall()
  15.  
  16. for x in myresult:
  17. print(x)