Jump to content

storing values of a request in a MySQL - database (an easy one)

Recommended Posts

i have a dictionary  - THIS IS obviously a python dictionary

an this has approx 8 000 lines with records


$ python printer.py
{'url': 'http://www.site1_com' 'cname': 'butcher', 'name': 'cheng', 'email': 'mail1@hotmail.com'}
{'url': 'http://www.site2_com' 'cname': 'dilbert', 'name': 'James', 'email': 'mail2@hotmail.com'}

i have a mysql-db up and runing in my opensuse

there i have created a db with the fields


i use the

import MySQLdb

i studied this documentation here: http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python

but i think this goes a bit over my head.

- well how can i get the data  ( in other words the dictionary) into the database?

love to hear from you

Link to comment
Share on other sites

  • 3 months later...
  • 3 years later...

Use MySQL Connector Python because it is official Oracle driver for MySQL for working with Python and it works with both Python 3 and Python 2

You need to match your dictionary key to your MySQL table column.

Please follow these steps : - 

  • Connect to MySQL from Python - Connect to MySQL through Python
  • Use parameterized Querty to insert different data tuples using the same query to increase the performance. 
  • Refer  - Insert data into MySQL Table using Python
  • Refer - How to Use parameterized Query

You need

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.