使用python调用mysql模块插入数据
安装MySQLdb python模块
[root@centos-1 history]# yum install -y MySQL-python
写一个python脚本关联mysql:
[root@centos-1 day2]# cat mysql2.py #!/bin/usr/python import MySQLdb as mysql con = mysql.connect(user="root",passwd="redhat", db="cml",host="localhost") con.autocomit(True) cur = con.cursor() for i in range(1,10): user = "user"+str(i) sql = ‘insert into cml values(%d,"%s")‘ %(i,user) cur.execute(sql)
本文出自 “第一个legehappy51cto博客” 博客,请务必保留此出处http://legehappy.blog.51cto.com/13251607/1982363
原文地址:http://legehappy.blog.51cto.com/13251607/1982363