Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Please help a noob with a script.

Please help a noob with a script.

Please help a noob with a script.


Firstly, I am very new to the Python world.

My scripts purpose is to export a MYSQL table from one server to another periodically as the original table is updated.

After trying to follow quite a few web examples...

I have the following.


import MySQLdb
import time
import re

  mconn = MySQLdb.connect (host = "",
                        user = "username",
                        passwd = "password",
                        db = "dbname")
  mcursor = mconn.cursor()

  mconn2 = MySQLdb.connect (host = "localhost",
                          user = "username",
                          passwd = "password",
                          db = "otherdbname")
  mcursor2 = mconn2.cursor()
except MySLQdb.Error, e:
  print "Error %d: %s" % (e.args[0], e.args[1])
  sys.exit (1)

# Read the values from original MYSQL database

mcursor = mconn.cursor (MySQLdb.cursors.DictCursor)
mcursor.execute ("SELECT brand, model FROM tblproducts WHERE Active = 1 Order by brand asc")
result_set = mcursor.fetchall ()
for row in result_set:
  print "%s, %s" % (row["brand"], row["model"])
print "Number of rows returned: %d" % mcursor.rowcount

mcursor.close ()

This indeed prints the results of the table to the screen.

I have tried many ways to incorporate an Insert into statement using the above loop.

If anyone has any better way for me to pipe the results of this first select into an insert. I would appreciate hearing any suggestions.


Remember- It's nice to be important,
but it's important to be nice :)

RE: Please help a noob with a script.

Sorry...as with all noobs learning something new. I jumped in way too early and posted for help. It turned out to be me attempting to insert string values in this format 'string'

I have worked out the above (simple) problem and will post the full script in case any other people pass by looking for some help.



Remember- It's nice to be important,
but it's important to be nice :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close