Python not inserting data's into mysql
Question: I am testing Python and Mysql in that i am able to create and delete table's
but i am unable to insert data in them.I searched stackoverflow and mostly
they suggest to use

    
    
    commit()
    

So i used it and even after i used the data is not inserted into the
database.Please help me. This is the code i use it creates the table but not
inserting data

    
    
    import MySQLdb
    db = MySQLdb.connect("localhost","user","password")
    cxn = MySQLdb.connect(db='test')
    cursor = cxn.cursor()
    cursor.execute("CREATE TABLE users(name VARCHAR(40),id VARCHAR(40))")
    cursor.execute("INSERT INTO users(name,id) VALUES('John','1')")
    db.commit()
    print "Opertion completed successfully"
    


Answer: Are `db` and `cxn` connections to the same database?

You should establish your connection using following:

    
    
    db = MySQLdb.connect(host="localhost",
                         db="test",
                         user="user",
                         passwd="password")
    

The cursor should then be derived from _this_ connection via:

    
    
    cursor = db.cursor()
    

I would hazard that your issue is coming from the ambiguity between `db` and
`cxn`.

