Last active
June 16, 2019 02:57
-
-
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 file contains hidden or 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
#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