Jump to content
apollo_moon_driver

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


[/code]

$ 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

url
cname
name
email



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

greetings

Share this post


Link to post
Share on other sites
Posted (edited)

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

Edited by Barand
Links removed

Share this post


Link to post
Share on other sites

Don't resurrect old posts. The poster of that question hasn't been back here for four years.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.