on duplicate key update
发布日期:2021-05-07 10:36:02 浏览次数:21 分类:原创文章

本文共 778 字,大约阅读时间需要 2 分钟。

 


import pymysql as pqfrom random_PersonName2 import random_nameimport datetimetry:    print('连接到mysql服务器...')    conn = pq.connect(        host='127.0.0.1',        port=3306,        user='root',        passwd='123456',        db='examples',        charset='utf8'    )    print('已连接上服务器!')    cursor = conn.cursor()    for x in range(6000):        currentTime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")        sqlstring="insert into `test_person`(`personName`, `lastUpdate`, `times`) VALUES('%s','%s','%d') on duplicate key update lastUpdate ='%s',times=times+1" % (random_name(),currentTime,1,currentTime)        cursor.execute(sqlstring)    conn.commit()    print('插入成功!')except Exception as e:    print(e)    conn.rollback()finally:    cursor.close()    conn.close()

 

上一篇:搜集整理随机产生人的姓名的2种方法
下一篇:mysql sql语句大全[留着学习用]

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年03月24日 17时20分01秒