Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> use aws_bill
- Database changed
- mysql> show tables;
- +--------------------+
- | Tables_in_aws_bill |
- +--------------------+
- | billing_info |
- +--------------------+
- mysql> desc billing_info;
- +----------+---------+------+-----+---------+-------+
- | Field | Type | Null | Key | Default | Extra |
- +----------+---------+------+-----+---------+-------+
- | RecordId | int(11) | NO | | NULL | |
- +----------+---------+------+-----+---------+-------+
- mydb = mysql.connector.connect(user='xxxx', password='xxxxx',
- host='xxxxx',
- database='aws_bill')
- cursor = mydb.cursor()
- try:
- with open(source) as csv_file:
- csv_reader = csv.reader(csv_file, delimiter=',')
- sql = "INSERT INTO billing_info (RecordId) VALUES (%s)"
- for row in csv_reader:
- row = (', '.join(row))
- print(row)
- cursor.execute(sql, row)
- except:
- mydb.rollback()
- finally:
- mydb.close()
- python3 .aws_billing.py
- 200176595756546201775238333
- mysql> select RecordId from billing_info;
- Empty set (0.00 sec)
- 203528424494971448426778962
- 203529863341009197771806423
- 203529974021473640029260511
- 203530250722634745672445063
- 203525214761502622966710100
- 203525122527782254417348410
- 203529365278919207614044035
- ...continues to the end of the file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement