-
-
Save Magnus167/2aa2ed1472618a74c8bfdae5c611365e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql.connector | |
# Establish a connection | |
connection = mysql.connector.connect( | |
host='your_host', | |
user='your_username', | |
password='your_password', | |
database='your_database' | |
) | |
# Create a buffered cursor | |
cursor = connection.cursor(buffered=True) | |
# Execute a query | |
cursor.execute("SELECT * FROM your_table") | |
# Fetch rows in batches | |
batch_size = 100 # Adjust the batch size as needed | |
rows = cursor.fetchmany(batch_size) | |
while rows: | |
for row in rows: | |
print(row) | |
rows = cursor.fetchmany(batch_size) | |
# Close the cursor and connection | |
cursor.close() | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/32627190/4417821