pymysql连接数据库

如下就是对数据库的操作

import pymysql
import time

conn = pymysql.connect(
    host="xxxxxxxx",
    user="xxxxx",
    password="xxxxxx",
    database="gxxxxx",
    charset="utf8"
)
cursor = conn.cursor()

mslist = []
with open("1102-1w.csv",'r') as dates:
    for line in dates:
        ms = line[-23:-1]
        mslist.append(ms)

#print(mslist)
# sql = "DELETE FROM RExx WHERE MSGSEQ='5'"
# cursor.execute(sql)
# conn.commit()
# print(cursor.rowcount)
i=0
for s in range(2005):
    print(s)
    #msgid = str(1000100001 + i)
    #print(msgid)
    MOBILE = str(15509000001+i)
    sql = "SELECT ID FROM RExx WHERE MOBILE='"+MOBILE+"'"
    print(sql)
    cursor.execute(sql)
    result = cursor.fetchall()
    j =s*5

    for row in result:
        print(row[0])
        ids = row[0]
        sql = "UPDATE RExx SET MSG_ID='"+mslist[j]+"' ,MSGSEQ='-1' WHERE ID='"+ids+"'"
        print(sql)
        cursor.execute(sql)
        conn.commit()
        j =j+1
    i = i+1

conn.close()

你可能感兴趣的:(python,java,数据库)