hzyimen
#coding=utf-8
import pymysql
import random
import time

def now():
    return time.strftime("%Y-%m-%d %H-")

conn = pymysql.connect(
host = "10.0.1.99", #你所在电脑的ip
port = 3306,#你所在电脑的端口
user = "root", #你所在数据库的用户名
passwd = "123456" ,#你所在电脑的密码
db = "health", #你所丰电脑的数据库
charset = "utf8"#默认编码方式utf-8
)
# 使用cursor()方法获取数据库的操作游标
cursor = conn.cursor()
# try:
for i in range(200,400):
    # 另一种插入数据方法,通过格式字符串传入值,此方式可以防止sql注入
    #这里一定要注意传入字符数
    sql = "insert into biz_teacher values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s)"    #这里指你要插入数据库字段的个数,有几个字段就是多少个%s
    cursor.execute(sql,(\'zsq20200326000\'+str(i),\'翠花测试\'+str(i),\'null\',\'330106008001\',\'31454035644b26a45291b18a36e9\'+str(random.randint(1,1000)),\'330106198906025527\',\'19817410529\', str(random.choice(["",""])), \'null\', \'hangzhou.aliyuncs.com/daily/thermometry/qrCodeImage/2020/03/06/74aaf37cd131239b3d2deb1ba4ad75ee.png\', \'null\', \'null\', \'4\', \'10\', \'2020-03-25 18:41:41\', \'2020-03-25 22:25:01\'))
   
    # INSERT INTO `biz_teacher` VALUES (\'7fdd323ece12442f89d0d806a001b4ee\', \'高语\', null, \'330106008002\', \'31454035644b26a45291b18a36e9e417\', \'330106198906021892\', \'19817410529\', \'男\', \'\', \'https://xdimage.oss-cn-hangzhou.aliyuncs.com/daily/thermometry/qrCodeImage/2020/03/05/7f5f082ccd49081ed9f71ffd50b071a2.png\', \'\', \'\', \'3\', \'10\', \'2020-03-05 16:49:37\', \'2020-03-06 22:43:02\');
    
# except Exception as e:
    # print("请重新执行!")
# 关闭游标
cursor.close()
# 提交事务
conn.commit()
# 关闭数据库连接
conn.close()
print(u"sql语句执行成功!")

 

分类:

技术点:

相关文章: