Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
Last active June 16, 2019 02:57
Show Gist options
  • Save imranbhullar/c632e03659df9b568df6d2431adbb31b to your computer and use it in GitHub Desktop.
Save imranbhullar/c632e03659df9b568df6d2431adbb31b to your computer and use it in GitHub Desktop.
This small python script will create 1million random numbers and push that to MySQL DB
#This small script will create 1million random numbers and push that to MySQL DB
import secrets
import pymysql
connection = pymysql.connect(host='dbserver.ourdomain.com',
user='dbuser',
password='dbpasswod',
db='DBNAME',
charset='charset',
port=3306,
cursorclass=pymysql.cursors.DictCursor)
# Generating 1million random numbers and insert those records in DB in bulk
for i in range(1000000):
title = (secrets.token_urlsafe())
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `sometable` (`column_name`) VALUES (%s)"
cursor.execute(sql, ((title)))
connection.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment