标签:
1、下载http://dev.mysql.com/downloads/connector/python/
import mysql.connector
config={‘host‘:‘127.0.0.1‘,#默认127.0.0.1
‘user‘:‘root‘,
‘password‘:‘123456‘,
‘port‘:3306 ,#默认即为3306
‘database‘:‘school_data‘,
‘charset‘:‘utf8‘#默认即为utf8
}
try:
cnn=mysql.connector.connect(**config);
print("连接成功");
cour=cnn.cursor();
value=(‘1211‘,‘asddd‘);
sql="""insert into dw (dwdm,dwmc) values (%s,%s)""";
cour.execute(sql,value);
#以下这一句很关键我少了这一句导致不报错,也插不进去数据,崩溃呀~~~
cnn.commit();
except mysql.connector.Error as e:
print(‘connect fails!{}‘.format(e))
finally:
cour.close();
cnn.close();
标签:
原文地址:http://www.cnblogs.com/prudent/p/prudent_2015_06_12.html