Hi,
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.
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.
Peter.
Remember- It's nice to be important,
but it's important to be nice
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.
Code:
import MySQLdb
import time
import re
try:
mconn = MySQLdb.connect (host = "192.168.1.3",
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.
Peter.
Remember- It's nice to be important,
but it's important to be nice