Advertisement
Typhoon

Python add record to MariaDB

May 12th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import pymysql
  4. # Open file with elail addresses : separate email @dress per line
  5. file = open('my_text_file.txt','r')
  6. fo = file.readlines()
  7. # Connect to the database
  8. connection = pymysql.connect(host='mariadb55.websupport.sk',
  9.                  port=3310,
  10.                              user='my_sql_user',
  11.                              passwd='my_sql_pass',
  12.                              db='my_sql_db',
  13.                              charset='utf8mb4',
  14.                              cursorclass=pymysql.cursors.DictCursor)
  15. # Read email from lines and push to DB
  16. for line in fo:
  17.     print line.replace('\n','')
  18.     with connection.cursor() as cursor:
  19.         # Create a new record
  20.         sql = "INSERT INTO email_unreg(email,kampan) VALUES (%s, %s)"
  21.         cursor.execute(sql, (line,'Nedorucene'))
  22.         connection.commit()
  23.         print "OK"
  24. print "Finish"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement