MYSQL insertIf you have bulk scripts for your email/sms like me, and you are sending to thousands of users, you will difintely will get stuck in the middle of the bulk notification or it will be very slow and unacceptable. First of all you must initiate only
ONE mysql connection. If you are inserting your data one by one, you're dead again! try to use executemany that will insert data into mySQL in bulk not one by one:client.executemany(
"""INSERT INTO email (name, spam, email, uid, email_content)
VALUES (%s, %s, %s, %s, %s)""",
[
("Ali", 0, '[email protected]', 1, 'EMAIL_CONTENT'),
("Reza", 1, '[email protected]', 2, 'EMAIL_CONTENT'),
("Mohsen", 1, '[email protected]', 3, 'EMAIL_CONTENT')
] )
Other note for bulk insertion is to avoid disk IO in case possible, and use redis, memcached or so on for inserting some data like user's phone or emails. It will tremendously improve performance of your bulk script.
#python #mysql #executemany #redis #bulk #email #sms
