安装MySQLdb python模块
[[email protected] history]# yum install -y MySQL-python
写一个python脚本关联mysql:
[[email protected] 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)
时间: 2024-11-09 23:55:40