Here is something I worked up to show you how to input data in MySQL via the command line in Python... should be easier to follow than the other example.
mysql> desc users;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| userid | varchar(10) | YES | | NULL | |
| fname | varchar(20) | YES | | NULL | |
| lname | varchar(25) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
mysql> select * from users;
Empty set (0.00 sec)
Executed below script...
#python db.py test test test
mysql> select * from users;
+--------+-------+-------+
| userid | fname | lname |
+--------+-------+-------+
| test | test | test |
+--------+-------+-------+
1 row in set (0.00 sec)
#! /usr/bin/python
import sys
import MySQLdb
id = sys.argv[1]
fname = sys.argv[2]
lname = sys.argv[3]
class Table:
def __init__(self, db, name):
self.db = db
self.name = name
self.dbc = self.db.cursor()
def additem(self, item):
sql = "INSERT INTO " + self.name + " VALUES ('" + id + "','" + fname + "','" + lname +"')"
self.dbc.execute(sql)
return
def main():
db = MySQLdb.connect(db="DBNAME",host="HOSTNAME",user="USERNAME",passwd="PASSWORD");
table = Table(db, "TABLENAME")
table.additem("TABLENAME")
if __name__ == '__main__':
main()
Let me know if you have trouble working in your specific tables... should be a matter of substitution of table name, fields, etc.