分类: 系统运维
2013-08-27 16:32:36
mport MySQLdb
try:
conn=MySQLdb.connect(host='localhost',port=3306,user='root',passwd='123456')
cur=conn.cursor()
cur.execute('create database if not exists python')
conn.select_db('python')
cur.execute('create table host(host varchar(20),user varchar(20),passwd varchar(30))')
value=['192.168.1.130','hans','123456']
cur.execute('insert into host values(%s,%s,%s)',value)
conn.commit()
result=cur.fetchall()
for line in result:
print line
cur.close()
conn.close()
except MySQLdb.Error,e:
print 'Mysql error msg:',e