在python脚本

时间:2016-01-15 16:06:54

标签: python mysql

我正在尝试在我的python脚本中执行多个MySql查询,并且我正在做我认为应该做的所有事情,但它仍然没有对我的table_a做任何事情。有什么见解吗?

import MySQLdb
conn = MySQLdb.connect("abc","bcd","cde","def")
x = conn.cursor()

try:
   operation = '''
    insert into table_a 
    (id, ip, hostname, username) 
    select distinct id, ip, hostname, username
    from table_b;

    update table_a 
    set 
    purpose = 'test purpose'
    , department = 'test department'
    where
    hostname = 'sample'
'''



   for result in x.execute(operation,multi = True):
      pass

   conn.commit()
except:
   conn.rollback()

conn.close()

0 个答案:

没有答案