Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table "control" like this in local mysql (IP = 192.168.137.165)
CSS
Card_ID     Time_in      Time_out     Index
  101         7:00         11:00       0
  102         7:15         11:00       1
  103         6:45         12:00       1


Local and remote tables "control" are the same table

How to select all rows with index = 1 and insert to remote mysql using python (IP=192.168.137.1)?

Code connect and insert mysql
Python
import MySQLdb
db_local = MySQLdb.connect("localhost","root","loot","luan_van")
db = MySQLdb.connect("192.168.137.1","root_a","","luan_van")
def add_remote():
   with db:
       cur = db.cursor()
       cur.execute("INSERT INTO control(Card_ID,Time_in) VALUES ('%d', NOW())" %num)
       return

I have ideas for backup database. If remote mysql alive, index = 0 and if remote mysql die, index = 1.

And if remote re-connect, I want to send data in local mysql to remote.So I want to just want to insert the line with index = 1

I can insert simple but I don't know insert multi-rows. Please help me. Thanks
Posted
Updated 8-Nov-14 21:42pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900