Jump to content

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
  • 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

Edited by Barand
Links removed
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.