python2 操作mysql

http://www.imooc.com/article/19509

import MySQLdb
conn = MySQLdb.connect(host='123.207.238.179', user='root', passwd='****', db='hue', charset='utf8')
cursor = conn.cursor()
sql_insert = 'insert into auth_user values(%d,"%s","%s",%d,"%s","%s","%s","%s",%d,%d,"%s")'
length = len(auth_user)
i = 0
while i < length:
    cursor.execute(sql_insert % tuple(auth_user.iloc[i,:]))
    i += 1
conn.commit()
cursor.close()
conn.close()

批量插入


你可能感兴趣的:(python2 操作mysql)