python mysql连接

#!/usr/bin/python
# coding=utf-8


import MySQLdb


conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='mysqladmin', db='testdb')
cursor = conn.cursor() #建造游标


cursor.execute( ' create table themysqldb(id varchar(20) primary key, name varchar(20) ) ' )
cursor.execute('insert into themysqldb(id, name)  values(%s, %s)', ['12', 'bobo'] )
conn.commit()
cursor.close()


cursor = conn.cursor()
cursor.execute('select * from themysqldb where id=12')
cursor.fetchall()
cursor.close()
conn.close()

你可能感兴趣的:(python,cursor,mysql,Python)