import mysql.connector
# Establishing connection to the database
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# Creating a cursor object
mycursor = mydb.cursor()
# SQL statement to select the first 10 records from the table
sql = "SELECT * FROM yourtable LIMIT 10"
# Executing the SQL command
mycursor.execute(sql)
# Fetching the results
results = mycursor.fetchall()
# Displaying the results
for row in results:
print(row)
# Closing the database connection
mydb.close()