使用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)
转载于:https://blog.51cto.com/legehappy/1982363