Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. mysql> use aws_bill
  2. Database changed
  3.  
  4. mysql> show tables;
  5. +--------------------+
  6. | Tables_in_aws_bill |
  7. +--------------------+
  8. | billing_info |
  9. +--------------------+
  10.  
  11. mysql> desc billing_info;
  12. +----------+---------+------+-----+---------+-------+
  13. | Field | Type | Null | Key | Default | Extra |
  14. +----------+---------+------+-----+---------+-------+
  15. | RecordId | int(11) | NO | | NULL | |
  16. +----------+---------+------+-----+---------+-------+
  17.  
  18. mydb = mysql.connector.connect(user='xxxx', password='xxxxx',
  19. host='xxxxx',
  20. database='aws_bill')
  21. cursor = mydb.cursor()
  22. try:
  23. with open(source) as csv_file:
  24. csv_reader = csv.reader(csv_file, delimiter=',')
  25. sql = "INSERT INTO billing_info (RecordId) VALUES (%s)"
  26. for row in csv_reader:
  27. row = (', '.join(row))
  28. print(row)
  29. cursor.execute(sql, row)
  30. except:
  31. mydb.rollback()
  32. finally:
  33. mydb.close()
  34.  
  35. python3 .aws_billing.py
  36. 200176595756546201775238333
  37.  
  38. mysql> select RecordId from billing_info;
  39. Empty set (0.00 sec)
  40.  
  41. 203528424494971448426778962
  42. 203529863341009197771806423
  43. 203529974021473640029260511
  44. 203530250722634745672445063
  45. 203525214761502622966710100
  46. 203525122527782254417348410
  47. 203529365278919207614044035
  48. ...continues to the end of the file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement