I'm creating a few different scripts that all interact with a central MySQL database to share data but I'm finding that some changes I make to the database wont propagate through or be readable to certain scripts until the database connection has been closed and re opened.
For example using the following code read_script
will only print items that have been added to the database using write_script
after I quit and restart write_script
. I'm new to MySQL so I'm not sure if there is a problem in my SQL or my python
read_script
connection = MySQLdb.connect(...)
while True:
cur = connection.cursor()
cur.execute("SELECT * FROM my_table")
print cur.fetchall()
cur.close()
write_script
connection = MySQLdb.connect(...)
cur = connection.cursor()
cur.execute("INSERT INTO my_table VALUES(some_data)")
cur.close()
connection.commit()
What do I need to do to ensure I get up to data data from the database?